Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/Examples/connect-to-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ const network = bcoin.Network.get('testnet');
const peer = bcoin.Peer.fromOptions({
network: 'testnet',
agent: 'my-subversion',
hasWitness: () => {
return false;
}
});

const addr = bcoin.net.NetAddress.fromHostname(process.argv[2], 'testnet');
Expand Down
2 changes: 1 addition & 1 deletion lib/blockchain/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ class Chain extends AsyncEmitter {
}
}

// Count sigops (legacy + scripthash? + witness?)
// Count sigops (legacy + scripthash?)
const txSigops = tx.getSigopsCount(view, state.flags);

if (txSigops > consensus.MAX_TX_SIGOPS) {
Expand Down
4 changes: 2 additions & 2 deletions lib/net/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ exports.LOCAL_SERVICES = 0
| exports.services.NETWORK;

/**
* Required services (network and segwit).
* Required services (network).
* @const {Number}
* @default
*/
Expand All @@ -122,7 +122,7 @@ exports.REQUIRED_SERVICES = 0
exports.USER_AGENT = `/bcash:${pkg.version}/`;

/**
* Max message size (~4mb with segwit, formerly 2mb)
* Max message size for non-block-like type messages.
* @const {Number}
* @default
*/
Expand Down
13 changes: 2 additions & 11 deletions lib/net/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ class Peer extends EventEmitter {

/**
* Calculate peer block inv type (filtered,
* compact, witness, or non-witness).
* compact or full block)
* @returns {Number}
*/

Expand All @@ -1243,15 +1243,6 @@ class Peer extends EventEmitter {
return invTypes.BLOCK;
}

/**
* Calculate peer tx inv type (witness or non-witness).
* @returns {Number}
*/

txType() {
return invTypes.TX;
}

/**
* Send `getdata` to peer.
* @param {InvItem[]} items
Expand Down Expand Up @@ -1294,7 +1285,7 @@ class Peer extends EventEmitter {
*/

getTX(hashes) {
this.getItems(this.txType(), hashes);
this.getItems(invTypes.TX, hashes);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions lib/primitives/mtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class MTX extends TX {
}

/**
* Build input script (or witness) templates (with
* Build input script templates (with
* OP_0 in place of signatures).
* @param {Number} index - Input index.
* @param {Coin|Output} coin
Expand All @@ -427,10 +427,6 @@ class MTX extends TX {
// Get the previous output's script
const prev = coin.script;

// This is easily the hardest part about
// building a transaction with segwit:
// figuring out where the redeem script
// and witness redeem scripts go.
const sh = prev.getScripthash();

if (sh) {
Expand Down
1 change: 0 additions & 1 deletion lib/primitives/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ class TX {

Script.verify(
input.script,
null,
coin.script,
this,
index,
Expand Down
5 changes: 2 additions & 3 deletions lib/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3054,9 +3054,8 @@ class Script {
}

/**
* Verify an input and output script, and a witness if present.
* Verify an input and output script
* @param {Script} input
* @param {Null} witness
* @param {Script} output
* @param {TX} tx
* @param {Number} index
Expand All @@ -3065,7 +3064,7 @@ class Script {
* @throws {ScriptError}
*/

static verify(input, witness, output, tx, index, value, flags) {
static verify(input, output, tx, index, value, flags) {
if (flags == null)
flags = Script.flags.STANDARD_VERIFY_FLAGS;

Expand Down
6 changes: 3 additions & 3 deletions lib/workers/packets.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ class SignPacket extends Packet {
*/

class SignResultPacket extends Packet {
constructor(total, witness, script) {
constructor() {
super();
this.cmd = packetTypes.SIGNRESULT;
this.total = total || 0;
this.script = script || [];
this.total = 0;
this.script = [];
}

fromTX(tx, total) {
Expand Down
2 changes: 1 addition & 1 deletion test/address-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('Address', function() {
);
});

it('should handle segwit non-zero padding in 8-to-5 conversion', () => {
it('should handle cashaddr non-zero padding in 8-to-5 conversion', () => {
const addr = 'bitcoincash:pruptvpkmxamee0f72sq40gm70wfr624zpu8adj8t6';
assert.throws(() => Address.fromString(addr, 'main'));

Expand Down
10 changes: 3 additions & 7 deletions test/data/tx-invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,17 @@

["FindAndDelete tests"],
["This is a test of FindAndDelete. The first tx is a spend of normal scriptPubKey and the second tx is a spend of bare P2WSH."],
["The redeemScript/witnessScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."],
["The redeemScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."],
["The signature is <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01> <pubkey>,"],
["where the pubkey is obtained through key recovery with sig and the wrong sighash."],
["This is to show that FindAndDelete is applied only to non-segwit scripts"],
["To show that the tests are 'correctly wrong', they should pass by modifying OP_CHECKSIG under interpreter.cpp"],
["by replacing (sigversion == SIGVERSION_BASE) with (sigversion != SIGVERSION_BASE)"],
["Non-segwit: wrong sighash (without FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"],
["Wrong sighash (without FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"],
[[["f18783ace138abac5d3a7a5cf08e88fe6912f267ef936452e0c27d090621c169", 7000, "HASH160 0x14 0x0c746489e2d83cdbb5b90b432773342ba809c134 EQUAL", 200000]],
"010000000169c12106097dc2e0526493ef67f21269fe888ef05c7a3a5dacab38e1ac8387f1581b0000b64830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e012103b12a1ec8428fc74166926318c15e17408fea82dbb157575e16a8c365f546248f4aad4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01ffffffff0101000000000000000000000000", "P2SH"],
["This is multisig version of the FindAndDelete tests"],
["Script is 2 CHECKMULTISIGVERIFY <sig1> <sig2> DROP"],
["52af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175"],
["Signature is 0 <sig1> <sig2> 2 <key1> <key2>"],
["Should pass by replacing (sigversion == SIGVERSION_BASE) with (sigversion != SIGVERSION_BASE) under OP_CHECKMULTISIG"],
["Non-segwit: wrong sighash (without FindAndDelete) = 4bc6a53e8e16ef508c19e38bba08831daba85228b0211f323d4cb0999cf2a5e8"],
["Wrong sighash (without FindAndDelete) = 4bc6a53e8e16ef508c19e38bba08831daba85228b0211f323d4cb0999cf2a5e8"],
[[["9628667ad48219a169b41b020800162287d2c0f713c04157e95c484a8dcb7592", 7000, "HASH160 0x14 0x5748407f5ca5cdca53ba30b79040260770c9ee1b EQUAL", 200000]],
"01000000019275cb8d4a485ce95741c013f7c0d28722160008021bb469a11982d47a662896581b0000fd6f01004830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c039596015221023fd5dd42b44769c5653cbc5947ff30ab8871f240ad0c0e7432aefe84b5b4ff3421039d52178dbde360b83f19cf348deb04fa8360e1bf5634577be8e50fafc2b0e4ef4c9552af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175ffffffff0101000000000000000000000000", "P2SH"],

Expand Down
7 changes: 3 additions & 4 deletions test/data/tx-valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,17 @@

["FindAndDelete tests"],
["This is a test of FindAndDelete. The first tx is a spend of normal P2SH and the second tx is a spend of bare P2WSH."],
["The redeemScript/witnessScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."],
["The redeemScript is CHECKSIGVERIFY <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01>."],
["The signature is <0x30450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01> <pubkey>,"],
["where the pubkey is obtained through key recovery with sig and correct sighash."],
["This is to show that FindAndDelete is applied only to non-segwit scripts"],
["Non-segwit: correct sighash (with FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"],
["Correct sighash (with FindAndDelete) = 1ba1fe3bc90c5d1265460e684ce6774e324f0fabdf67619eda729e64e8b6bc08"],
[[["f18783ace138abac5d3a7a5cf08e88fe6912f267ef936452e0c27d090621c169", 7000, "HASH160 0x14 0x0c746489e2d83cdbb5b90b432773342ba809c134 EQUAL", 200000]],
"010000000169c12106097dc2e0526493ef67f21269fe888ef05c7a3a5dacab38e1ac8387f1581b0000b64830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0121037a3fb04bcdb09eba90f69961ba1692a3528e45e67c85b200df820212d7594d334aad4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01ffffffff0101000000000000000000000000", "P2SH"],
["This is multisig version of the FindAndDelete tests"],
["Script is 2 CHECKMULTISIGVERIFY <sig1> <sig2> DROP"],
["52af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175"],
["Signature is 0 <sig1> <sig2> 2 <key1> <key2>"],
["Non-segwit: correct sighash (with FindAndDelete) = 1d50f00ba4db2917b903b0ec5002e017343bb38876398c9510570f5dce099295"],
["Correct sighash (with FindAndDelete) = 1d50f00ba4db2917b903b0ec5002e017343bb38876398c9510570f5dce099295"],
[[["9628667ad48219a169b41b020800162287d2c0f713c04157e95c484a8dcb7592", 7000, "HASH160 0x14 0x5748407f5ca5cdca53ba30b79040260770c9ee1b EQUAL", 200000]],
"01000000019275cb8d4a485ce95741c013f7c0d28722160008021bb469a11982d47a662896581b0000fd6f01004830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c03959601522102cd74a2809ffeeed0092bc124fd79836706e41f048db3f6ae9df8708cefb83a1c2102e615999372426e46fd107b76eaf007156a507584aa2cc21de9eee3bdbd26d36c4c9552af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175ffffffff0101000000000000000000000000", "P2SH"],

Expand Down
7 changes: 2 additions & 5 deletions test/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ describe('Node', function() {
const json = await node.rpc.call({
method: 'getblocktemplate',
params: [
{rules: ['segwit']}
{rules: []}
],
id: '1'
}, {});
Expand Down Expand Up @@ -776,10 +776,7 @@ describe('Node', function() {
const tx1 = TX.fromRaw(rawTX1, 'hex');
const dummyPeer = Peer.fromOptions({
network: 'regtest',
agent: 'my-subversion',
hasWitness: () => {
return false;
}
agent: 'my-subversion'
});
const txItem = new InvItem(invTypes.TX, tx1.hash());
await node.sendTX(tx1); // add TX to inventory
Expand Down
2 changes: 1 addition & 1 deletion test/script-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('Script', function() {

let err;
try {
Script.verify(input, null, output, tx, 0, value, flags);
Script.verify(input, output, tx, 0, value, flags);
} catch (e) {
err = e;
}
Expand Down