add lang identifiers to examples.md with gulp
This commit is contained in:
parent
fe4bbf3d72
commit
bac81ce88e
141
examples.md
141
examples.md
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
|
@ -29,7 +30,6 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#Armory.js
|
#Armory.js
|
||||||
|
@ -101,7 +101,6 @@ for (var i = 0; i < 5; i++) {
|
||||||
console.log(Address.fromPubKey(b.pubkey).as('base58'));
|
console.log(Address.fromPubKey(b.pubkey).as('base58'));
|
||||||
b = b.next();
|
b = b.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#ConnectionTor.js
|
#ConnectionTor.js
|
||||||
|
@ -145,7 +144,6 @@ dns.resolve('dnsseed.bluematt.me', function(err, seeds) {
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#CreateAndSignTx-Multisig.js
|
#CreateAndSignTx-Multisig.js
|
||||||
|
@ -172,6 +170,7 @@ var run = function() {
|
||||||
address: input.addr,
|
address: input.addr,
|
||||||
txid: "39c71ebda371f75f4b854a720eaf9898b237facf3c2b101b58cd4383a44a6adc",
|
txid: "39c71ebda371f75f4b854a720eaf9898b237facf3c2b101b58cd4383a44a6adc",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
ts: 1396288753,
|
||||||
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
||||||
amount: 0.4296,
|
amount: 0.4296,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
|
@ -213,7 +212,7 @@ var run = function() {
|
||||||
//save scriptPubKey
|
//save scriptPubKey
|
||||||
var scriptPubKey = tx.outs[0].s.toString('hex');
|
var scriptPubKey = tx.outs[0].s.toString('hex');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* REDDEEM TX
|
* REDDEEM TX
|
||||||
*/
|
*/
|
||||||
|
@ -221,6 +220,7 @@ var run = function() {
|
||||||
address: input.addr,
|
address: input.addr,
|
||||||
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
||||||
vout: 0,
|
vout: 0,
|
||||||
|
ts: 1396288753,
|
||||||
scriptPubKey: scriptPubKey,
|
scriptPubKey: scriptPubKey,
|
||||||
amount: 0.05,
|
amount: 0.05,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
|
@ -256,8 +256,8 @@ if (typeof module !== 'undefined') {
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
////
|
|
||||||
|
|
||||||
|
////
|
||||||
```
|
```
|
||||||
|
|
||||||
#CreateAndSignTx-PayToPubkeyHash.js
|
#CreateAndSignTx-PayToPubkeyHash.js
|
||||||
|
@ -276,6 +276,7 @@ var run = function() {
|
||||||
address: "mqSjTad2TKbPcKQ3Jq4kgCkKatyN44UMgZ",
|
address: "mqSjTad2TKbPcKQ3Jq4kgCkKatyN44UMgZ",
|
||||||
txid: "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
txid: "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
ts: 1394719301,
|
||||||
scriptPubKey: "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ac",
|
scriptPubKey: "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ac",
|
||||||
amount: 0.01,
|
amount: 0.01,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
|
@ -334,8 +335,8 @@ if (typeof module !== 'undefined') {
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
////
|
|
||||||
|
|
||||||
|
////
|
||||||
```
|
```
|
||||||
|
|
||||||
#CreateAndSignTx-PayToScriptHash.js
|
#CreateAndSignTx-PayToScriptHash.js
|
||||||
|
@ -363,6 +364,7 @@ var run = function() {
|
||||||
address: "n2hoFVbPrYQf7RJwiRy1tkbuPPqyhAEfbp",
|
address: "n2hoFVbPrYQf7RJwiRy1tkbuPPqyhAEfbp",
|
||||||
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
ts: 1396290442,
|
||||||
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
||||||
amount: 0.3795,
|
amount: 0.3795,
|
||||||
confirmations: 7
|
confirmations: 7
|
||||||
|
@ -419,7 +421,7 @@ var run = function() {
|
||||||
//save scriptPubKey
|
//save scriptPubKey
|
||||||
var scriptPubKey = tx.outs[0].s.toString('hex');
|
var scriptPubKey = tx.outs[0].s.toString('hex');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* REDDEEM TX
|
* REDDEEM TX
|
||||||
*/
|
*/
|
||||||
|
@ -427,6 +429,7 @@ var run = function() {
|
||||||
address: p2shAddress,
|
address: p2shAddress,
|
||||||
txid: "c2e50d1c8c581d8c4408378b751633f7eb86687fc5f0502be7b467173f275ae7",
|
txid: "c2e50d1c8c581d8c4408378b751633f7eb86687fc5f0502be7b467173f275ae7",
|
||||||
vout: 0,
|
vout: 0,
|
||||||
|
ts: 1396375187,
|
||||||
scriptPubKey: scriptPubKey,
|
scriptPubKey: scriptPubKey,
|
||||||
amount: 0.05,
|
amount: 0.05,
|
||||||
confirmations: 1
|
confirmations: 1
|
||||||
|
@ -491,7 +494,6 @@ if (typeof module !== 'undefined') {
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#CreateKey.js
|
#CreateKey.js
|
||||||
|
@ -500,6 +502,8 @@ if (typeof module !== 'undefined') {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
|
@ -544,7 +548,6 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#CreateScript.js
|
#CreateScript.js
|
||||||
|
@ -627,7 +630,6 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#ECIES.js
|
#ECIES.js
|
||||||
|
@ -664,7 +666,6 @@ if (typeof module !== 'undefined') {
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#ElectrumMPK.js
|
#ElectrumMPK.js
|
||||||
|
@ -682,7 +683,6 @@ var key0 = mpk.generatePubKey(0);
|
||||||
var addr0 = Address.fromPubKey(key0);
|
var addr0 = Address.fromPubKey(key0);
|
||||||
|
|
||||||
console.log(addr0.as('base58'));
|
console.log(addr0.as('base58'));
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#HierarchicalKey.js
|
#HierarchicalKey.js
|
||||||
|
@ -772,7 +772,67 @@ if (typeof module !== 'undefined') {
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#NetworkMonitor.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var NetworkMonitor = bitcore.NetworkMonitor;
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
networkName: 'testnet',
|
||||||
|
host: 'localhost',
|
||||||
|
port: 18333
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var nm = new NetworkMonitor.create(config);
|
||||||
|
// monitor incoming transactions to http://tpfaucet.appspot.com/ donation address
|
||||||
|
nm.incoming('msj42CCGruhRsFrGATiUuh25dtxYtnpbTx', function(tx) {
|
||||||
|
console.log('Donation to tpfaucet! '+JSON.stringify(tx.getStandardizedObject()));
|
||||||
|
});
|
||||||
|
|
||||||
|
// connect to bitcoin network and start listening
|
||||||
|
nm.start();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#Opreturn.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
var coinUtil = bitcore.util;
|
||||||
|
var Script = bitcore.Script;
|
||||||
|
var network = bitcore.networks.testnet;
|
||||||
|
|
||||||
|
var script = 'OP_RETURN 58434c524e4748530000000000000000000000010000000005f5e100';
|
||||||
|
var s = Script.fromHumanReadable(script);
|
||||||
|
var result = (s.classify() == Script.TX_RETURN)
|
||||||
|
console.log("Is op_return:", result);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#PayToScriptHashAddress.js
|
#PayToScriptHashAddress.js
|
||||||
|
@ -796,7 +856,6 @@ var addrStr = addr.as('base58');
|
||||||
|
|
||||||
// This outputs the "address" of thescript
|
// This outputs the "address" of thescript
|
||||||
console.log(addrStr);
|
console.log(addrStr);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#PeerDiscovery.js
|
#PeerDiscovery.js
|
||||||
|
@ -809,7 +868,6 @@ var peerman = new PeerManager();
|
||||||
peerman.discover({
|
peerman.discover({
|
||||||
limit: 12
|
limit: 12
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#PeerManager.js
|
#PeerManager.js
|
||||||
|
@ -863,7 +921,6 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#Rpc.js
|
#Rpc.js
|
||||||
|
@ -902,7 +959,6 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#Script.js
|
#Script.js
|
||||||
|
@ -961,7 +1017,54 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#ScriptInterpreter.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
var coinUtil = bitcore.util;
|
||||||
|
var Script = bitcore.Script;
|
||||||
|
var ScriptInterpreter = bitcore.ScriptInterpreter;
|
||||||
|
var network = bitcore.networks.testnet;
|
||||||
|
|
||||||
|
|
||||||
|
// using "static" method
|
||||||
|
var scriptPubKeyHR = '0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71 EQUAL';
|
||||||
|
var scriptPubKey = Script.fromHumanReadable(scriptPubKeyHR);
|
||||||
|
|
||||||
|
var scriptSigHR = '0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71';
|
||||||
|
var scriptSig = Script.fromHumanReadable(scriptSigHR);
|
||||||
|
|
||||||
|
ScriptInterpreter.verifyFull(scriptSig, scriptPubKey, undefined, undefined,
|
||||||
|
undefined, undefined, function(err, result) {
|
||||||
|
console.log('script verified successfully? ', result)
|
||||||
|
});
|
||||||
|
|
||||||
|
// using an instance
|
||||||
|
scriptPubKeyHR = '0x26 0x554e5a49500370e53982a1d5201829562c5d9eebf256eb755b92c9b1449afd99f9f8c3265631 DROP HASH256 0x20 0x34b4f6042e1bcfc6182ee2727a3d0069a9071385bc07b318f57e77a28ffa13ac EQUAL';
|
||||||
|
scriptPubKey = Script.fromHumanReadable(scriptPubKeyHR);
|
||||||
|
|
||||||
|
scriptSigHR = '0x41 0x0470e53982a1d5201829562c5d9eebf256eb755b92c9b1449afd99f9f8c3265631142f3bf6954e3bec4bdad1a1a197bf90904a1e6f06c209eb477e2fde00d26691';
|
||||||
|
scriptSig = Script.fromHumanReadable(scriptSigHR);
|
||||||
|
|
||||||
|
var si = new ScriptInterpreter();
|
||||||
|
si.verifyFull(scriptSig, scriptPubKey, undefined, undefined,
|
||||||
|
undefined, function(err, result) {
|
||||||
|
console.log('script verified successfully? ', result)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#SendTx.js
|
#SendTx.js
|
||||||
|
@ -1060,7 +1163,7 @@ var run = function() {
|
||||||
// finally, send transaction to the bitcoin network
|
// finally, send transaction to the bitcoin network
|
||||||
conn.sendTx(tx);
|
conn.sendTx(tx);
|
||||||
|
|
||||||
// for now, the network will not respond in any case
|
// for now, the network won't respond in any case
|
||||||
// (transaction accepted, transaction rejected)
|
// (transaction accepted, transaction rejected)
|
||||||
// in the future, we may listen to 'reject' message
|
// in the future, we may listen to 'reject' message
|
||||||
// see https://gist.github.com/gavinandresen/7079034
|
// see https://gist.github.com/gavinandresen/7079034
|
||||||
|
@ -1075,7 +1178,6 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#SimpleP2Pmonitor.js
|
#SimpleP2Pmonitor.js
|
||||||
|
@ -1154,7 +1256,6 @@ listen('inv', function(event, log) {
|
||||||
log('Received message inv (%s invs)', event.message.count);
|
log('Received message inv (%s invs)', event.message.count);
|
||||||
console.log(event.message.invs);
|
console.log(event.message.invs);
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#VanityAddress.js
|
#VanityAddress.js
|
||||||
|
@ -1163,6 +1264,7 @@ listen('inv', function(event, log) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
|
@ -1188,5 +1290,4 @@ module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -9,7 +9,7 @@ var format = es.through(
|
||||||
if (file.isStream()) return this.emit('error', new Error('Streaming not supported'));
|
if (file.isStream()) return this.emit('error', new Error('Streaming not supported'));
|
||||||
|
|
||||||
//add indentation
|
//add indentation
|
||||||
var contents = "\t" + file.contents.toString("utf8").split("\n").join("\n\t");
|
var contents = "\n```js\n\n" + file.contents.toString("utf8").split("\n").join("\n") + "```\n";
|
||||||
//add header
|
//add header
|
||||||
contents = ["#", path.basename(file.path), "\n", contents].join("");
|
contents = ["#", path.basename(file.path), "\n", contents].join("");
|
||||||
file.contents = new Buffer(contents, "utf8");
|
file.contents = new Buffer(contents, "utf8");
|
||||||
|
|
Loading…
Reference in New Issue