Skip to content

Commit

Permalink
Merge branch 'xrpTxOrder' of github.com:leolambo/bitcore
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Aug 5, 2024
2 parents eb337f6 + bd9199e commit 6c66035
Show file tree
Hide file tree
Showing 7 changed files with 904 additions and 817 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 @@ -477,7 +477,9 @@ export class Utils {
multisigContractAddress,
multiSendContractAddress,
isTokenSwap,
gasLimit
gasLimit,
multiTx,
outputOrder
} = txp;
const recipients = outputs.map(output => {
return {
Expand Down Expand Up @@ -511,6 +513,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 @@ -356,7 +356,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: 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
Loading

0 comments on commit 6c66035

Please sign in to comment.