Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bitpay/bitcore into p2trWalletSup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
kajoseph committed Aug 5, 2024
2 parents 44f8bf4 + ce4a229 commit be25564
Show file tree
Hide file tree
Showing 9 changed files with 991 additions and 794 deletions.
27 changes: 26 additions & 1 deletion packages/bitcore-wallet-client/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ export class Utils {
multisigContractAddress,
multiSendContractAddress,
isTokenSwap,
gasLimit
gasLimit,
multiTx,
outputOrder
} = txp;
const recipients = outputs.map(output => {
return {
Expand Down Expand Up @@ -519,6 +521,29 @@ export class Utils {
gasLimit
};
unsignedTxs.push(Transactions.create({ ...txp, ...multiSendParams }));
} else if (multiTx) {
// Add unsigned transactions in outputOrder
for (let index = 0; index < outputOrder.length; index++) {
const outputIdx = outputOrder[index];
if (!outputs?.[outputIdx]) {
throw new Error('Output index out of range');
}
const recepient = {
amount: outputs[outputIdx].amount,
address: outputs[outputIdx].toAddress,
tag: outputs[outputIdx].tag
}
const _tag = recepient?.tag || destinationTag;
const rawTx = Transactions.create({
...txp,
...recepient,
tag: _tag ? Number(_tag) : undefined,
chain: _chain,
nonce: Number(txp.nonce) + Number(index),
recipients: [recepient]
});
unsignedTxs.push(rawTx);
}
} else {
for (let index = 0; index < recipients.length; index++) {
const rawTx = Transactions.create({
Expand Down
4 changes: 3 additions & 1 deletion packages/bitcore-wallet-service/src/lib/chain/btc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ export class BtcChain implements IChain {
// set nLockTime (only txp.version>=4)
if (txp.lockUntilBlockHeight) t.lockUntilBlockHeight(txp.lockUntilBlockHeight);
}

if (txp.multiTx) {
throw Errors.MULTI_TX_UNSUPPORTED;
}
/*
* txp.inputs clean txp.input
* removes possible nSequence number (BIP68)
Expand Down
6 changes: 5 additions & 1 deletion packages/bitcore-wallet-service/src/lib/chain/eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ export class EthChain implements IChain {
tokenAddress,
multisigContractAddress,
multiSendContractAddress,
isTokenSwap
isTokenSwap,
multiTx
} = txp;
if (multiTx) {
throw Errors.MULTI_TX_UNSUPPORTED;
}
const isERC20 = tokenAddress && !payProUrl && !isTokenSwap;
const isETHMULTISIG = multisigContractAddress;
const chain = isETHMULTISIG ? `${this.chain}MULTISIG` : isERC20 ? `${this.chain}ERC20` : this.chain;
Expand Down
30 changes: 18 additions & 12 deletions packages/bitcore-wallet-service/src/lib/chain/xrp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class XrpChain implements IChain {

checkDust(output, opts) { }

checkScriptOutput(output) {}
checkScriptOutput(output) { }

getFee(server, wallet, opts) {
return new Promise((resolve, reject) => {
Expand All @@ -135,24 +135,30 @@ export class XrpChain implements IChain {
}

getBitcoreTx(txp, opts = { signed: true }) {
const { destinationTag, outputs } = txp;
const { destinationTag, outputs, outputOrder, multiTx } = txp;
const chain = 'XRP';
const recipients = outputs.map(output => {
return {
amount: output.amount,
address: output.toAddress,
tag: output.tag
};
});
const unsignedTxs = [];
for (let index = 0; index < recipients.length; index++) {
const _tag = recipients[0]?.tag || destinationTag;
const length = multiTx ? outputOrder.length : outputs.length;
for (let index = 0; index < length; index++) {
let outputIdx = index;
if (multiTx) {
outputIdx = outputOrder[index];
}
if (!outputs?.[outputIdx]) {
throw new Error('Output index out of range');
}
const recepient = {
amount: outputs[outputIdx].amount,
address: outputs[outputIdx].toAddress,
tag: outputs[outputIdx].tag
}
const _tag = recepient?.tag || destinationTag;
const rawTx = Transactions.create({
...txp,
tag: _tag ? Number(_tag) : undefined,
chain,
nonce: Number(txp.nonce) + Number(index),
recipients: [recipients[index]]
recipients: [recepient]
});
unsignedTxs.push(rawTx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface Errors<T> {
LOCKED_OP_FEE: T;
HISTORY_LIMIT_EXCEEDED: T;
MAIN_ADDRESS_GAP_REACHED: T;
MULTI_TX_UNSUPPORTED: T;
NETWORK_SUSPENDED: T;
NOT_AUTHORIZED: T;
SCRIPT_OP_RETURN: T;
Expand Down Expand Up @@ -92,6 +93,7 @@ const errors: Errors<string> = {
LOCKED_FUNDS: 'Funds are locked by pending transaction proposals',
HISTORY_LIMIT_EXCEEDED: 'Requested page limit is above allowed maximum',
MAIN_ADDRESS_GAP_REACHED: 'Maximum number of consecutive addresses without activity reached',
MULTI_TX_UNSUPPORTED: 'Desired chain does not support multi transaction proposals',
NETWORK_SUSPENDED: '$network operations are currently suspended. Please check status.bitpay.com for further updates.',
NOT_AUTHORIZED: 'Not authorized',
SCRIPT_OP_RETURN: 'The only supported script is OP_RETURN',
Expand Down
11 changes: 11 additions & 0 deletions packages/bitcore-wallet-service/src/lib/expressapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,17 @@ export class ExpressApp {
});
});

router.post('/v1/service/sardine/getSupportedTokens', async (req, res) => {
let server, response;
try {
server = getServer(req, res);
response = await server.sardineGetSupportedTokens(req);
return res.json(response);
} catch (ex) {
return returnError(ex, res, req);
}
});

router.post('/v1/service/sardine/currencyLimits', (req, res) => {
let server;
try {
Expand Down
11 changes: 7 additions & 4 deletions packages/bitcore-wallet-service/src/lib/model/txproposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ITxProposal {
script?: string;
tag?: string;
}>;
outputOrder: number;
outputOrder: number[];
walletM: number;
walletN: number;
requiredSignatures: number;
Expand Down Expand Up @@ -188,9 +188,12 @@ export class TxProposal {
x.outputs = _.map(opts.outputs, output => {
return _.pick(output, ['amount', 'toAddress', 'message', 'data', 'gasLimit', 'script']);
});
let numOutputs = x.outputs.length + 1;
let numOutputs = x.outputs.length;
if (!opts.multiTx) {
numOutputs++;
}
if (x.instantAcceptanceEscrow) {
numOutputs = numOutputs + 1;
numOutputs++;
}
x.outputOrder = _.range(numOutputs);
if (!opts.noShuffleOutputs) {
Expand Down Expand Up @@ -244,7 +247,7 @@ export class TxProposal {
// XRP
x.destinationTag = opts.destinationTag;
x.invoiceID = opts.invoiceID;
x.multiTx = opts.multiTx;
x.multiTx = opts.multiTx; // proposal contains multiple transactions

return x;
}
Expand Down
39 changes: 39 additions & 0 deletions packages/bitcore-wallet-service/src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5799,6 +5799,40 @@ export class WalletService implements IWalletService {
});
}

sardineGetSupportedTokens(req): Promise<any> {
return new Promise((resolve, reject) => {
const keys = this.sardineGetKeys(req);
const API = keys.API;
const CLIENT_ID = keys.CLIENT_ID;
const SECRET_KEY = keys.SECRET_KEY;

const secret = `${CLIENT_ID}:${SECRET_KEY}`;
const secretBase64 = Buffer.from(secret).toString('base64');

const headers = {
'Content-Type': 'application/json',
'Authorization': `Basic ${secretBase64}`,
};

const URL: string = API + '/v1/supported-tokens';

this.request.get(
URL,
{
headers,
json: true
},
(err, data) => {
if (err) {
return reject(err.body ? err.body : err);
} else {
return resolve(data.body ? data.body : data);
}
}
);
});
}

sardineGetOrdersDetails(req): Promise<any> {
return new Promise((resolve, reject) => {
const keys = this.sardineGetKeys(req);
Expand Down Expand Up @@ -5887,6 +5921,11 @@ export class WalletService implements IWalletService {
Authorization: 'ApiKey ' + API_KEY
};

if (req.body && req.body.payment_methods && Array.isArray(req.body.payment_methods)) {
// Workaround to fix older versions of the app
req.body.payment_methods = req.body.payment_methods.map(item => item === 'simplex_account' ? 'sepa_open_banking' : item);
}

this.request.post(
API + '/wallet/merchant/v2/quote',
{
Expand Down
Loading

0 comments on commit be25564

Please sign in to comment.