Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('will get results using bitcore.Transaction', function() {
var bitcoind = new BitcoinService(baseConfig);
var wif = 'L2Gkw3kKJ6N24QcDuH4XDqt9cTqsKTVNDGz1CRZhk9cq4auDUbJy';
var privkey = bitcore.PrivateKey.fromWIF(wif);
var inputAddress = privkey.toAddress(bitcore.Networks.testnet);
var outputAddress = bitcore.Address('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br');
var tx = bitcore.Transaction();
tx.from({
txid: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
outputIndex: 0,
script: bitcore.Script(inputAddress),
address: inputAddress.toString(),
satoshis: 5000000000
});
tx.to(outputAddress, 5000000000);
tx.sign(privkey);
var addresses = bitcoind._getAddressesFromTransaction(tx);
addresses.length.should.equal(2);
addresses[0].should.equal(inputAddress.toString());
addresses[1].should.equal(outputAddress.toString());
});
it('will handle non-standard script types', function() {
it('will handle non-standard script types', function() {
var bitcoind = new BitcoinService(baseConfig);
var tx = bitcore.Transaction();
tx.addInput(bitcore.Transaction.Input({
prevTxId: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
script: bitcore.Script('OP_TRUE'),
outputIndex: 1,
output: {
script: bitcore.Script('OP_TRUE'),
satoshis: 5000000000
}
}));
tx.addOutput(bitcore.Transaction.Output({
script: bitcore.Script('OP_TRUE'),
satoshis: 5000000000
}));
var addresses = bitcoind._getAddressesFromTransaction(tx);
addresses.length.should.equal(0);
});
it('will handle unparsable script types or missing input script', function() {
it('will return unique values', function() {
var bitcoind = new BitcoinService(baseConfig);
var tx = bitcore.Transaction();
var address = bitcore.Address('2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br');
tx.addOutput(bitcore.Transaction.Output({
script: bitcore.Script(address),
satoshis: 5000000000
}));
tx.addOutput(bitcore.Transaction.Output({
script: bitcore.Script(address),
satoshis: 5000000000
}));
var addresses = bitcoind._getAddressesFromTransaction(tx);
addresses.length.should.equal(1);
});
});
clients[1].getMainAddresses({}, function(err, walletAddresses) {
var args = http.lastCall.args[0];
var data = BitcorePayPro.Payment.decode(args.body);
var pay = new BitcorePayPro();
var p = pay.makePayment(data);
var refund_to = p.get('refund_to');
refund_to.length.should.equal(1);
refund_to = refund_to[0];
var amount = refund_to.get('amount')
amount.low.should.equal(404500);
amount.high.should.equal(0);
var s = refund_to.get('script');
s = new Bitcore.Script(s.buffer.slice(s.offset, s.limit));
var addr = new Bitcore.Address.fromScript(s, 'testnet');
addr.toString().should.equal(
walletAddresses[walletAddresses.length - 1].address);
done();
});
});
clients[1].getMainAddresses({}, function(err, walletAddresses) {
var args = http.lastCall.args[0];
var data = BitcorePayPro.Payment.decode(args.body);
var pay = new BitcorePayPro();
var p = pay.makePayment(data);
var refund_to = p.get('refund_to');
refund_to.length.should.equal(1);
refund_to = refund_to[0];
var amount = refund_to.get('amount')
amount.low.should.equal(404500);
amount.high.should.equal(0);
var s = refund_to.get('script');
s = new Bitcore.Script(s.buffer.slice(s.offset, s.limit));
var addr = new Bitcore.Address.fromScript(s, 'testnet');
addr.toString().should.equal(
walletAddresses[walletAddresses.length - 1].address);
done();
});
});
_.each(tx.outputs, function(o) {
if (o.script) {
var s = new Bitcore.Script(new Buffer(o.script, 'hex'));
var a = s.toAddress(network);
if (a) {
allAddresses[a] = true;
}
}
});
});
Sender.prototype._buildRedeemScript = function() {
this._redeemScript = new bitcore.Script();
this._redeemScript.add(Opcode.OP_IF)
.add(this._receiverPublicKeys[0].toBuffer())
.add(Opcode.OP_CHECKSIG)
.add(Opcode.OP_ELSE)
.add(this._convertExpirationTimeStamp())
.add(Opcode.OP_CHECKLOCKTIMEVERIFY)
.add(Opcode.OP_DROP)
.add(Opcode.OP_ENDIF)
.add(this._senderPublicKeys[0].toBuffer())
.add(Opcode.OP_CHECKSIG);
};
var scriptHash = bitcore.crypto.Hash.sha256ripemd160(script.toBuffer());
var addressMainnet = bitcore.Address.fromScriptHash(scriptHash, bitcore.Networks.mainnet);
$('#result-address-mainnet').val(addressMainnet);
$('#result-address-mainnet-explorer').attr('href', BLOCKEXPLORER_MAINNET_ADDRESS_ENDPOINT.replace(':ADDRESS:', addressMainnet));
var addressTestnet = bitcore.Address.fromScriptHash(scriptHash, bitcore.Networks.testnet);
$('#result-address-testnet').val(addressTestnet);
$('#result-address-testnet-explorer').attr('href', BLOCKEXPLORER_TESTNET_ADDRESS_ENDPOINT.replace(':ADDRESS:', addressTestnet));
var interpreter = new bitcore.Script.Interpreter();
interpreter.set({script: script});
var err = '';
var result = true;
for(; interpreter.pc');
var executed = (new bitcore.Script()).set({chunks: interpreter.script.chunks.slice(interpreter.pc-1, interpreter.pc)}).toString();
var remaining = (new bitcore.Script()).set({chunks: interpreter.script.chunks.slice(interpreter.pc)}).toString();
$('#result-steps tbody').append('' + [interpreter.pc, stack, executed, remaining].join('') + '');
if(!result) break;
}
if(!result) {
err += 'Script ended with error.';
} else {
if(interpreter.stack.length == 0) {
result = false;
err += 'The resulting stack is empty.';
} else {
var ret = interpreter.stack.pop();
if(!bitcore.Script.Interpreter.castToBool(ret)) {
result = false;
err += 'The resulting top stack item is FALSE.';
}
}