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
13 changes: 11 additions & 2 deletions packages/bitcore-wallet-service/src/lib/chain/eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,16 @@ export class EthChain implements IChain {
return cb(null, 0);
}

refreshTxData(_server: WalletService, txp, _opts, cb) {
return cb(null, txp);
refreshTxData(server: WalletService, txp, opts, cb) {
// set latest nonce
server._getTransactionCount(opts.wallet, txp.from, (err, nonce) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint: extra space before txp.from

if (err) return cb(err);
nonce = Number(nonce);
if (!Number.isInteger(nonce)) {
return cb(new ClientError(Errors.codes.INVALID_NONCE, `Nonce is not a number. Found ${ nonce }`));
}
txp.nonce = nonce;
return cb(null, txp);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Errors<T> {
INSUFFICIENT_FUNDS_FOR_FEE: T;
INVALID_ADDRESS: T;
INVALID_CHANGE_ADDRESS: T;
INVALID_NONCE: T;
KEY_IN_COPAYER: T;
LOCKED_FUNDS: T;
// Polygon Errors
Expand Down Expand Up @@ -89,6 +90,7 @@ const errors: Errors<string> = {
LOCKED_OP_FEE: 'Your linked OP wallet does not have enough ETH for fee',
INVALID_ADDRESS: 'Invalid address',
INVALID_CHANGE_ADDRESS: 'Invalid change address',
INVALID_NONCE: 'Invalid nonce',
KEY_IN_COPAYER: 'Key already registered',
LOCKED_FUNDS: 'Funds are locked by pending transaction proposals',
HISTORY_LIMIT_EXCEEDED: 'Requested page limit is above allowed maximum',
Expand Down
11 changes: 9 additions & 2 deletions packages/bitcore-wallet-service/src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,10 @@ export class WalletService implements IWalletService {
// SOL is skipped since its a non necessary field that is expected to be provided by the client.
if (!opts.nonce && !Constants.SVM_CHAINS[wallet.chain.toUpperCase()]) {
try {
if (Constants.EVM_CHAINS[wallet.chain.toUpperCase()]) {
// if nonce mangement is done by BWS, default to refreshing nonce on txp publish
opts.refreshOnPublish = true;
}
opts.nonce = await ChainService.getTransactionCount(this, wallet, opts.from);
} catch (error) {
return next(error);
Expand Down Expand Up @@ -2868,6 +2872,7 @@ export class WalletService implements IWalletService {
if (!txp.isTemporary() && !txp.isRepublishEnabled()) return cb(null, txp);

const copayer = wallet.getCopayer(this.copayerId);
const initialStatus = txp.status;

let raw;
try {
Expand Down Expand Up @@ -2897,6 +2902,7 @@ export class WalletService implements IWalletService {
ChainService.checkTxUTXOs(this, txp, opts, err => {
if (err) return cb(err);
txp.status = 'pending';
opts.wallet = wallet;
ChainService.refreshTxData(this, txp, opts, (err, txp) => {
if (err) return cb(err);
if (txp.isRepublishEnabled() && !txp.prePublishRaw) {
Expand All @@ -2905,7 +2911,8 @@ export class WalletService implements IWalletService {
}
this.storage.storeTx(this.walletId, txp, err => {
if (err) return cb(err);
const action = txp.isRepublishEnabled() && txp.prePublishRaw ? 'UpdatedTxProposal' : 'NewTxProposal';

const action = initialStatus === 'pending' ? 'UpdatedTxProposal' : 'NewTxProposal';
this._notifyTxProposalAction(action, txp, () => {
if (txp.coin == 'bch' && txp.changeAddress) {
const format = opts.noCashAddr ? 'copay' : 'cashaddr';
Expand Down Expand Up @@ -3166,7 +3173,7 @@ export class WalletService implements IWalletService {
try {
const txps = await this.getPendingTxsPromise({});
for (let t of txps) {
if (t.id !== txp.id && t.nonce <= txp.nonce && t.status !== 'rejected') {
if (t.id !== txp.id && t.nonce <= txp.nonce && t.status !== 'rejected' && !t.isRepublishEnabled()) {
return cb(Errors.TX_NONCE_CONFLICT);
}
}
Expand Down