Skip to content

Commit f57147f

Browse files
author
Justin Kook
committed
merge master into ETH
2 parents c4f0d43 + ad92f94 commit f57147f

File tree

7 files changed

+94
-13
lines changed

7 files changed

+94
-13
lines changed

packages/bitcore-lib/lib/address.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ Address._classifyFromVersion = function(buffer) {
181181

182182
if (buffer.length > 21) {
183183
var info = Bech32.decode(buffer.toString('utf8'));
184+
if (info.version !== 0) {
185+
throw new TypeError('Only witness v0 addresses are supported.');
186+
}
184187
if (info.data.length === 20) {
185188
version.type = Address.PayToWitnessPublicKeyHash;
186189
} else if (info.data.length === 32) {

packages/bitcore-lib/test/address_witness.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ describe('Witness Address', function() {
6464
'bc1q9225rawdn2dlwsk3dd8phudsap6vjp7fgwh455'
6565
];
6666

67+
//livenet incorrect witness version
68+
var incorrectWitnessVersions = [
69+
'bc1p9225pawdj2dlwsk3dd8phudsap6vjp7fr0y9q5',
70+
'bc1p9225pawdn2dlwsk3dd8phudsap6vjp7fhqj5wnrpg457qjq0ycvsjzekl8'
71+
];
72+
6773
//testnet valid
6874
var P2WPKHTestnet = [
6975
'tb1q5lrlddcjejvu0qyx0f5fg59zj89danlxtt058g',
@@ -132,6 +138,14 @@ describe('Witness Address', function() {
132138
}
133139
});
134140

141+
it('should not validate if witness version is not 0', function() {
142+
for (var i = 0; i < incorrectWitnessVersions.length; i++) {
143+
var error = Address.getValidationError(incorrectWitnessVersions[i], 'livenet', 'witnesspubkeyhash');
144+
should.exist(error);
145+
error.message.should.equal('Only witness v0 addresses are supported.');
146+
}
147+
});
148+
135149
it('should not validate on a network mismatch', function() {
136150
var error, i;
137151
for (i = 0; i < P2WPKHLivenet.length; i++) {

packages/bitcore-node/test/verification/db-repair.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ import { BitcoinP2PWorker } from "../../src/modules/bitcoin/p2p";
8888
}
8989
break;
9090
case 'COIN_HEIGHT_MISMATCH':
91+
92+
case 'CORRUPTED_BLOCK':
9193
case 'MISSING_BLOCK':
9294
case 'MISSING_TX':
9395
case 'MISSING_COIN_FOR_TXID':

packages/bitcore-node/test/verification/db-verify.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,42 @@ type ErrorType = {
2020

2121
export async function validateDataForBlock(blockNum: number, log = false) {
2222
let success = true;
23-
const blockTxs = await TransactionStorage.collection.find({ chain, network, blockHeight: blockNum }).toArray();
23+
const [block, blockTxs, blocksForHeight] = await Promise.all([
24+
BitcoinBlockStorage.collection.findOne({ chain, network, height: blockNum, processed: true }),
25+
TransactionStorage.collection.find({ chain, network, blockHeight: blockNum }).toArray(),
26+
BitcoinBlockStorage.collection.countDocuments({
27+
chain,
28+
network,
29+
height: blockNum,
30+
processed: true
31+
})
32+
]);
2433
const blockTxids = blockTxs.map(t => t.txid);
25-
const coinsForTx = await CoinStorage.collection.find({ chain, network, mintTxid: { $in: blockTxids } }).toArray();
26-
const mempoolTxs = await TransactionStorage.collection
27-
.find({ chain, network, blockHeight: -1, txid: { $in: blockTxids } })
28-
.toArray();
34+
const firstHash = blockTxs[0].blockHash;
35+
const [coinsForTx, mempoolTxs, blocksForHash] = await Promise.all([
36+
CoinStorage.collection.find({ chain, network, mintTxid: { $in: blockTxids } }).toArray(),
37+
TransactionStorage.collection.find({ chain, network, blockHeight: -1, txid: { $in: blockTxids } }).toArray(),
38+
BitcoinBlockStorage.collection.countDocuments({ chain, network, hash: firstHash })
39+
]);
2940

3041
const seenTxs = {} as { [txid: string]: ITransaction };
3142
const errors = new Array<ErrorType>();
3243

44+
if (!block || block.transactionCount != blockTxs.length) {
45+
const error = {
46+
model: 'block',
47+
err: true,
48+
type: 'CORRUPTED_BLOCK',
49+
payload: { blockNum }
50+
};
51+
52+
errors.push(error);
53+
54+
if (log) {
55+
console.log(JSON.stringify(error));
56+
}
57+
}
58+
3359
for (const tx of mempoolTxs) {
3460
success = false;
3561
const error = { model: 'transaction', err: true, type: 'DUPE_TRANSACTION', payload: { tx, blockNum } };
@@ -125,12 +151,6 @@ export async function validateDataForBlock(blockNum: number, log = false) {
125151
}
126152
}
127153

128-
const blocksForHeight = await BitcoinBlockStorage.collection.countDocuments({
129-
chain,
130-
network,
131-
height: blockNum,
132-
processed: true
133-
});
134154
if (blocksForHeight === 0) {
135155
success = false;
136156
const error = {
@@ -161,7 +181,6 @@ export async function validateDataForBlock(blockNum: number, log = false) {
161181
//blocks with same hash
162182
if (blockTxs.length > 0) {
163183
const hashFromTx = blockTxs[0].blockHash;
164-
const blocksForHash = await BitcoinBlockStorage.collection.countDocuments({ chain, network, hash: hashFromTx });
165184
if (blocksForHash > 1) {
166185
success = false;
167186
const error = { model: 'block', err: true, type: 'DUPE_BLOCKHASH', payload: { hash: hashFromTx, blockNum } };

packages/bitcore-wallet-client/src/lib/api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export class API extends EventEmitter {
4949
keyDerivationOk: boolean;
5050
noSign: any;
5151
password: any;
52+
bp_partner: string;
53+
bp_partner_version: string;
5254

5355
static PayPro = PayPro;
5456
static Key = Key;
@@ -71,6 +73,9 @@ export class API extends EventEmitter {
7173
this.logLevel = opts.logLevel || 'silent';
7274
this.supportStaffWalletId = opts.supportStaffWalletId;
7375

76+
this.bp_partner = opts.bp_partner;
77+
this.bp_partner_version = opts.bp_partner_version;
78+
7479
this.request = new Request(opts.baseUrl || BASE_URL, { r: opts.request });
7580
log.setLevel(this.logLevel);
7681
}
@@ -1731,6 +1736,9 @@ export class API extends EventEmitter {
17311736
coin: txp.coin || 'btc',
17321737
network: txp.network || 'livenet',
17331738

1739+
bp_partner: this.bp_partner,
1740+
bp_partner_version: this.bp_partner_version,
1741+
17341742
// for testing
17351743
request: this.request
17361744
},

packages/bitcore-wallet-client/src/lib/paypro.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,16 @@ export class PayPro {
280280

281281
opts.headers = {
282282
'Content-Type': JSON_PAYMENT_CONTENT_TYPE,
283-
'Accept': JSON_PAYMENT_ACK_CONTENT_TYPE,
283+
'Accept': JSON_PAYMENT_ACK_CONTENT_TYPE
284284
};
285285

286+
if (opts.bp_partner){
287+
opts.headers['BP_PARTNER'] = opts.bp_partner;
288+
if (opts.bp_partner_version){
289+
opts.headers['BP_PARTNER_VERSION'] = opts.bp_partner_version;
290+
}
291+
}
292+
286293
opts.body = JSON.stringify({
287294
currency: COIN,
288295
transactions: [

packages/bitcore-wallet-client/test/api.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ helpers.newClient = (app) => {
4848
return new Client({
4949
baseUrl: '/bws/api',
5050
request: request(app),
51+
bp_partner: 'xxx',
52+
bp_partner_version: 'yyy',
5153
// logLevel: 'debug',
5254
});
5355
};
@@ -3327,6 +3329,32 @@ describe('client API', () => {
33273329
});
33283330
});
33293331
});
3332+
3333+
it('Should set bp_partner', (done) => {
3334+
clients[0].getTxProposals({}, (err, txps) => {
3335+
should.not.exist(err);
3336+
var changeAddress = txps[0].changeAddress.address;
3337+
let signatures = keys[0].sign(clients[0].getRootPath(), txps[0]);
3338+
clients[0].pushSignatures(txps[0], signatures, (err, xx, paypro) => {
3339+
should.not.exist(err);
3340+
let signatures = keys[1].sign(clients[1].getRootPath(), txps[0]);
3341+
clients[1].pushSignatures(xx, signatures, (err, yy, paypro) => {
3342+
should.not.exist(err);
3343+
3344+
yy.status.should.equal('accepted');
3345+
let spy = sinon.spy(Client.PayPro, 'request');
3346+
clients[1].broadcastTxProposal(yy, (err, zz, memo) => {
3347+
should.not.exist(err);
3348+
var args = spy.lastCall.args[0];
3349+
var data = args.headers;
3350+
data.BP_PARTNER.should.equal('xxx');
3351+
data.BP_PARTNER_VERSION.should.equal('yyy');
3352+
done();
3353+
});
3354+
});
3355+
});
3356+
});
3357+
});
33303358
});
33313359

33323360

0 commit comments

Comments
 (0)