Ryan X. Charles
11 years ago
9 changed files with 372 additions and 264 deletions
@ -0,0 +1,52 @@ |
|||
'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 getAddrStr = function(s) { |
|||
var addrStrs = []; |
|||
var type = s.classify(); |
|||
var addr; |
|||
|
|||
switch (type) { |
|||
case Script.TX_PUBKEY: |
|||
var chunk = s.captureOne(); |
|||
addr = new Address(network.addressPubkey, coinUtil.sha256ripe160(chunk)); |
|||
addrStrs.push(addr.toString()); |
|||
break; |
|||
case Script.TX_PUBKEYHASH: |
|||
addr = new Address(network.addressPubkey, s.captureOne()); |
|||
addrStrs.push(addr.toString()); |
|||
break; |
|||
case Script.TX_SCRIPTHASH: |
|||
addr = new Address(network.addressScript, s.captureOne()); |
|||
addrStrs.push(addr.toString()); |
|||
break; |
|||
case Script.TX_MULTISIG: |
|||
var chunks = s.capture(); |
|||
chunks.forEach(function(chunk) { |
|||
var a = new Address(network.addressPubkey, coinUtil.sha256ripe160(chunk)); |
|||
addrStrs.push(a.toString()); |
|||
}); |
|||
break; |
|||
case Script.TX_UNKNOWN: |
|||
console.log('tx type unkown'); |
|||
break; |
|||
} |
|||
return addrStrs; |
|||
}; |
|||
|
|||
var script = 'DUP HASH160 0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71 EQUALVERIFY CHECKSIG'; |
|||
var s = Script.fromHumanReadable(script); |
|||
console.log(getAddrStr(s)[0]); // mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT
|
|||
}; |
|||
|
|||
module.exports.run = run; |
|||
if (require.main === module) { |
|||
run(); |
|||
} |
@ -0,0 +1,17 @@ |
|||
'use strict'; |
|||
|
|||
var backup = console.log; |
|||
var ebackup = console.error; |
|||
var nop = function() {}; |
|||
var mute = function() { |
|||
console.log = nop; |
|||
console.error = nop; |
|||
}; |
|||
|
|||
var unmute = function() { |
|||
console.log = backup; |
|||
console.error = ebackup; |
|||
}; |
|||
|
|||
module.exports.mute = mute; |
|||
module.exports.unmute = unmute; |
@ -0,0 +1,25 @@ |
|||
'use strict'; |
|||
|
|||
var chai = chai || require('chai'); |
|||
var should = chai.should(); |
|||
var mute = require('./mute').mute; |
|||
var unmute = require('./mute').unmute; |
|||
|
|||
var examples = [ |
|||
'Address', |
|||
'PeerManager', |
|||
'Rpc', |
|||
'SendTx', |
|||
'Script', |
|||
]; |
|||
|
|||
describe('Examples', function() { |
|||
before(mute); |
|||
after(unmute); |
|||
examples.forEach(function(example) { |
|||
it('valid '+example, function() { |
|||
var ex = require('../examples/'+example); |
|||
ex.run.should.not.throw(); |
|||
}); |
|||
}); |
|||
}); |
Loading…
Reference in new issue