* Fixes address.js to be able to deal with testnet P2SH addresses
* Enhanced address.js testsuite...now also verifies address versions * Enhances README to show how to run test suite
This commit is contained in:
parent
db8b38803c
commit
786198f130
4 changed files with 45 additions and 31 deletions
|
@ -12,7 +12,7 @@ var Address = function (bytes, version) {
|
|||
}
|
||||
else if (typeof bytes === 'string') {
|
||||
this.hash =
|
||||
bytes.length <= 34 ? base58.checkDecode(bytes)
|
||||
bytes.length <= 35 ? base58.checkDecode(bytes)
|
||||
: bytes.length <= 40 ? conv.hexToBytes(bytes)
|
||||
: util.error('Bad input');
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ var Opcode = require('./opcode');
|
|||
var util = require('./util');
|
||||
var conv = require('./convert');
|
||||
var Address = require('./address');
|
||||
var network = require('./network');
|
||||
|
||||
var Script = function(data) {
|
||||
this.buffer = data || [];
|
||||
|
@ -295,20 +296,20 @@ Script.prototype.writeBytes = function(data) {
|
|||
Script.createOutputScript = function(address) {
|
||||
var script = new Script();
|
||||
address = new Address(address);
|
||||
// Standard pay-to-pubkey-hash
|
||||
if (!address.version) {
|
||||
if (address.version == network.mainnet.p2shVersion || address.version == network.testnet.p2shVersion) {
|
||||
// Standard pay-to-script-hash
|
||||
script.writeOp(Opcode.map.OP_HASH160);
|
||||
script.writeBytes(address.hash);
|
||||
script.writeOp(Opcode.map.OP_EQUAL);
|
||||
}
|
||||
else {
|
||||
// Standard pay-to-pubkey-hash
|
||||
script.writeOp(Opcode.map.OP_DUP);
|
||||
script.writeOp(Opcode.map.OP_HASH160);
|
||||
script.writeBytes(address.hash);
|
||||
script.writeOp(Opcode.map.OP_EQUALVERIFY);
|
||||
script.writeOp(Opcode.map.OP_CHECKSIG);
|
||||
}
|
||||
// Standard pay-to-script-hash
|
||||
else {
|
||||
script.writeOp(Opcode.map.OP_HASH160);
|
||||
script.writeBytes(address.hash);
|
||||
script.writeOp(Opcode.map.OP_EQUAL);
|
||||
}
|
||||
return script;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue