From a63eecfbf12a291526ed272791d565fd1fda14b8 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Tue, 22 Aug 2023 14:51:01 -0700 Subject: [PATCH 1/8] Stop populating the zcash spendTargets The core is responsible for doing this, not the plugins. --- src/zcash/ZcashEngine.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/zcash/ZcashEngine.ts b/src/zcash/ZcashEngine.ts index ecbae2469..417de7b5a 100644 --- a/src/zcash/ZcashEngine.ts +++ b/src/zcash/ZcashEngine.ts @@ -330,14 +330,6 @@ export class ZcashEngine extends CurrencyEngine< // ********************************** // Create the unsigned EdgeTransaction - const spendTargets = edgeSpendInfo.spendTargets.map(si => ({ - uniqueIdentifier: si.uniqueIdentifier, - memo: si.memo, - nativeAmount: si.nativeAmount ?? '0', - currencyCode, - publicAddress - })) - const txNativeAmount = mul(totalTxAmount, '-1') const edgeTransaction: EdgeTransaction = { @@ -350,7 +342,6 @@ export class ZcashEngine extends CurrencyEngine< networkFee: this.networkInfo.defaultNetworkFee, ourReceiveAddresses: [], signedTx: '', - spendTargets, walletId: this.walletId } From 652258c7ff210dbc9053b14effc8864e60c6bf0d Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 17 Aug 2023 11:24:24 -0700 Subject: [PATCH 2/8] Alphabetize EdgeTransaction instances --- src/algorand/AlgorandEngine.ts | 18 ++--- src/binance/BinanceEngine.ts | 24 +++---- src/eos/EosEngine.ts | 58 +++++++-------- src/ethereum/EthereumEngine.ts | 12 ++-- src/ethereum/EthereumNetwork.ts | 28 ++++---- src/filecoin/FilecoinEngine.ts | 30 ++++---- src/fio/FioEngine.ts | 34 ++++----- src/hedera/HederaEngine.ts | 24 +++---- src/polkadot/PolkadotEngine.ts | 18 ++--- src/ripple/RippleEngine.ts | 56 +++++++-------- src/solana/SolanaEngine.ts | 18 ++--- src/stellar/StellarEngine.ts | 26 +++---- src/tezos/TezosEngine.ts | 22 +++--- src/tron/TronEngine.ts | 120 ++++++++++++++++---------------- src/zcash/ZcashEngine.ts | 18 ++--- test/tezos/engine.test.ts | 12 ++-- 16 files changed, 259 insertions(+), 259 deletions(-) diff --git a/src/algorand/AlgorandEngine.ts b/src/algorand/AlgorandEngine.ts index 0007d9972..712f56bd7 100644 --- a/src/algorand/AlgorandEngine.ts +++ b/src/algorand/AlgorandEngine.ts @@ -331,16 +331,16 @@ export class AlgorandEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: id, - date: roundTime, - currencyCode, blockHeight: confirmedRound, - nativeAmount, + currencyCode, + date: roundTime, isSend, + nativeAmount, networkFee, ourReceiveAddresses, parentNetworkFee, signedTx: '', + txid: id, walletId: this.walletId } @@ -623,17 +623,17 @@ export class AlgorandEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount, + currencyCode, + date: 0, isSend: true, + nativeAmount, networkFee, + otherParams, ourReceiveAddresses: [], parentNetworkFee, signedTx: '', - otherParams, + txid: '', walletId: this.walletId } diff --git a/src/binance/BinanceEngine.ts b/src/binance/BinanceEngine.ts index 46a680990..3ce7a150d 100644 --- a/src/binance/BinanceEngine.ts +++ b/src/binance/BinanceEngine.ts @@ -183,18 +183,18 @@ export class BinanceEngine extends CurrencyEngine< if (blockHeight < 0) blockHeight = 0 const unixTimestamp = new Date(tx.blockTime).getTime() / 1000 const edgeTransaction: EdgeTransaction = { - txid: tx.hash, - date: unixTimestamp, - currencyCode, blockHeight, - nativeAmount: netNativeAmount, + currencyCode, + date: unixTimestamp, isSend: netNativeAmount.startsWith('-'), - networkFee: nativeNetworkFee, - ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction - signedTx: '', metadata: { notes: tx.memo }, + nativeAmount: netNativeAmount, + networkFee: nativeNetworkFee, + ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction + signedTx: '', + txid: tx.hash, walletId: this.walletId } @@ -432,16 +432,16 @@ export class BinanceEngine extends CurrencyEngine< // Create the unsigned EdgeTransaction const edgeTransaction: EdgeTransaction = { - txid: '', // txid - date: 0, // date - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount, // nativeAmount + currencyCode, // currencyCode + date: 0, // date isSend: nativeAmount.startsWith('-'), + nativeAmount, // nativeAmount networkFee: nativeNetworkFee, // networkFee, supposedly fixed + otherParams, // otherParams ourReceiveAddresses: [], // ourReceiveAddresses signedTx: '', // signedTx - otherParams, // otherParams + txid: '', // txid walletId: this.walletId } diff --git a/src/eos/EosEngine.ts b/src/eos/EosEngine.ts index 0ee1d6066..a8355a07d 100644 --- a/src/eos/EosEngine.ts +++ b/src/eos/EosEngine.ts @@ -258,21 +258,21 @@ export class EosEngine extends CurrencyEngine { } const edgeTransaction: EdgeTransaction = { - txid: trxId, - date: Date.parse(blockTime) / 1000, - currencyCode, blockHeight: blockNum > 0 ? blockNum : 0, - nativeAmount, + currencyCode, + date: Date.parse(blockTime) / 1000, isSend: nativeAmount.startsWith('-'), - networkFee: '0', - parentNetworkFee: '0', - ourReceiveAddresses, - signedTx: '', - otherParams: {}, metadata: { name, notes: memo }, + nativeAmount, + networkFee: '0', + otherParams: {}, + ourReceiveAddresses, + parentNetworkFee: '0', + signedTx: '', + txid: trxId, walletId: this.walletId } @@ -339,20 +339,20 @@ export class EosEngine extends CurrencyEngine { } const edgeTransaction: EdgeTransaction = { - txid, - date, - currencyCode, blockHeight, - nativeAmount, + currencyCode, + date, isSend: nativeAmount.startsWith('-'), - networkFee: '0', - parentNetworkFee: '0', - ourReceiveAddresses, - signedTx: '', metadata: { notes: memo }, + nativeAmount, + networkFee: '0', otherParams: { fromAddress: from, toAddress: to }, + ourReceiveAddresses, + parentNetworkFee: '0', + signedTx: '', + txid, walletId: this.walletId } @@ -870,19 +870,19 @@ export class EosEngine extends CurrencyEngine { } ] const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode: this.currencyInfo.currencyCode, blockHeight: 0, - nativeAmount: '-3', + currencyCode: this.currencyInfo.currencyCode, + date: 0, isSend: true, + nativeAmount: '-3', networkFee: '0', - ourReceiveAddresses: [], - signedTx: '', otherParams: { actions: transferActions, signatures: [] }, + ourReceiveAddresses: [], + signedTx: '', + txid: '', walletId: this.walletId } const signedTx = await this.signTx(edgeTransaction, privateKeys) @@ -1041,19 +1041,19 @@ export class EosEngine extends CurrencyEngine { nativeAmount = `-${nativeAmount}` const edgeTransaction: EdgeTransaction = { - txid: '', // txid - date: 0, // date - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount, // nativeAmount + currencyCode, // currencyCode + date: 0, // date isSend: nativeAmount.startsWith('-'), + nativeAmount, // nativeAmount networkFee, // networkFee - ourReceiveAddresses: [], // ourReceiveAddresses - signedTx: '', // signedTx otherParams: { actions: transferActions, signatures: [] }, + ourReceiveAddresses: [], // ourReceiveAddresses + signedTx: '', // signedTx + txid: '', // txid walletId: this.walletId } this.warn( diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index 9d332497e..ea85c864c 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -1020,17 +1020,17 @@ export class EthereumEngine extends CurrencyEngine< // const edgeTransaction: EdgeTransaction = { - txid: '', // txid - date: 0, // date - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount, // nativeAmount + currencyCode, // currencyCode + date: 0, // date + feeRateUsed: getFeeRateUsed(miningFees.gasPrice, otherParams.gas), isSend: nativeAmount.startsWith('-'), + nativeAmount, // nativeAmount networkFee: nativeNetworkFee, // networkFee - feeRateUsed: getFeeRateUsed(miningFees.gasPrice, otherParams.gas), + otherParams, // otherParams ourReceiveAddresses: [], // ourReceiveAddresses signedTx: '', // signedTx - otherParams, // otherParams + txid: '', // txid walletId: this.walletId } diff --git a/src/ethereum/EthereumNetwork.ts b/src/ethereum/EthereumNetwork.ts index ffaf55a30..a6fa98435 100644 --- a/src/ethereum/EthereumNetwork.ts +++ b/src/ethereum/EthereumNetwork.ts @@ -344,21 +344,21 @@ export class EthereumNetwork { if (blockHeight < 0) blockHeight = 0 const edgeTransaction: EdgeTransaction = { - txid, - date: parseInt(tx.timeStamp), - currencyCode, blockHeight, - nativeAmount, - isSend: nativeAmount.startsWith('-'), - networkFee, + currencyCode, + date: parseInt(tx.timeStamp), feeRateUsed: gasPrice != null ? getFeeRateUsed(gasPrice, tx.gas, tx.gasUsed) : undefined, - parentNetworkFee, + isSend: nativeAmount.startsWith('-'), + nativeAmount, + networkFee, + otherParams, ourReceiveAddresses, + parentNetworkFee, signedTx: '', - otherParams, + txid, walletId: this.walletId } @@ -440,17 +440,17 @@ export class EthereumNetwork { } const edgeTransaction: EdgeTransaction = { - txid: tokenTransfer.relationships.transaction.data.id, - date: tokenTransfer.attributes.blockCreationTime, - currencyCode, blockHeight, - nativeAmount: netNativeAmount, + currencyCode, + date: tokenTransfer.attributes.blockCreationTime, isSend: netNativeAmount.startsWith('-'), + nativeAmount: netNativeAmount, networkFee, + otherParams, ourReceiveAddresses, - signedTx: '', parentNetworkFee, - otherParams, + signedTx: '', + txid: tokenTransfer.relationships.transaction.data.id, walletId: this.walletId } diff --git a/src/filecoin/FilecoinEngine.ts b/src/filecoin/FilecoinEngine.ts index 98ee6be49..3d3975e30 100644 --- a/src/filecoin/FilecoinEngine.ts +++ b/src/filecoin/FilecoinEngine.ts @@ -192,16 +192,16 @@ export class FilecoinEngine extends CurrencyEngine< const txNativeAmount = mul(add(nativeAmount, networkFee), '-1') const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount: txNativeAmount, + currencyCode, + date: 0, isSend: true, + nativeAmount: txNativeAmount, networkFee, - ourReceiveAddresses: [], otherParams, + ourReceiveAddresses: [], signedTx: '', + txid: '', walletId: this.walletId } @@ -473,16 +473,16 @@ export class FilecoinEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: messageDetails.cid, - date: messageDetails.timestamp, - currencyCode: this.currencyInfo.currencyCode, blockHeight: messageDetails.height, - nativeAmount, + currencyCode: this.currencyInfo.currencyCode, + date: messageDetails.timestamp, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, + otherParams: {}, ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction signedTx: '', - otherParams: {}, + txid: messageDetails.cid, walletId: this.walletId } @@ -509,16 +509,16 @@ export class FilecoinEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: message.cid, - date: message.block_time, - currencyCode: this.currencyInfo.currencyCode, blockHeight: message.height, - nativeAmount, + currencyCode: this.currencyInfo.currencyCode, + date: message.block_time, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, + otherParams: {}, ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction signedTx: '', - otherParams: {}, + txid: message.cid, walletId: this.walletId } diff --git a/src/fio/FioEngine.ts b/src/fio/FioEngine.ts index 51ef20d45..66f847905 100644 --- a/src/fio/FioEngine.ts +++ b/src/fio/FioEngine.ts @@ -483,16 +483,16 @@ export class FioEngine extends CurrencyEngine { otherParams.meta.isTransferProcessed = true const edgeTransaction: EdgeTransaction = { - txid: action.action_trace.trx_id, - date: this.getUTCDate(action.block_time) / 1000, - currencyCode, blockHeight: action.block_num > 0 ? action.block_num : 0, - nativeAmount, + currencyCode, + date: this.getUTCDate(action.block_time) / 1000, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, + otherParams, ourReceiveAddresses, signedTx: '', - otherParams, + txid: action.action_trace.trx_id, walletId: this.walletId } this.addTransaction(currencyCode, edgeTransaction) @@ -570,16 +570,16 @@ export class FioEngine extends CurrencyEngine { otherParams.meta.isFeeProcessed = true const edgeTransaction: EdgeTransaction = { - txid: action.action_trace.trx_id, - date: this.getUTCDate(action.block_time) / 1000, - currencyCode, blockHeight: action.block_num > 0 ? action.block_num : 0, - nativeAmount, + currencyCode, + date: this.getUTCDate(action.block_time) / 1000, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, - signedTx: '', - ourReceiveAddresses: [], otherParams, + ourReceiveAddresses: [], + signedTx: '', + txid: action.action_trace.trx_id, walletId: this.walletId } this.addTransaction(currencyCode, edgeTransaction) @@ -1678,19 +1678,19 @@ export class FioEngine extends CurrencyEngine { } const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount: sub(`-${quantity}`, `${fee}`), + currencyCode, + date: 0, isSend: true, + nativeAmount: sub(`-${quantity}`, `${fee}`), networkFee: `${fee}`, - ourReceiveAddresses: [], - signedTx: '', otherParams: { ...otherParams, txParams }, + ourReceiveAddresses: [], + signedTx: '', + txid: '', walletId: this.walletId } diff --git a/src/hedera/HederaEngine.ts b/src/hedera/HederaEngine.ts index 5137493cc..f60f2c015 100644 --- a/src/hedera/HederaEngine.ts +++ b/src/hedera/HederaEngine.ts @@ -365,18 +365,18 @@ export class HederaEngine extends CurrencyEngine< if (gt(nativeAmount, '0')) ourReceiveAddresses.push(accountIdStr) txs.push({ - txid: hashToTxid(base64.parse(tx.transaction_hash)), - date: parseInt(tx.valid_start_timestamp), - currencyCode: this.currencyInfo.currencyCode, // currencyCode blockHeight: 1, // blockHeight - nativeAmount, + currencyCode: this.currencyInfo.currencyCode, // currencyCode + date: parseInt(tx.valid_start_timestamp), isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee: tx.charged_tx_fee.toString(), // networkFee - ourReceiveAddresses, // ourReceiveAddresses - signedTx: '', // signedTx otherParams: { consensusAt: tx.consensus_timestamp }, + ourReceiveAddresses, // ourReceiveAddresses + signedTx: '', // signedTx + txid: hashToTxid(base64.parse(tx.transaction_hash)), walletId: this.walletId }) } @@ -459,21 +459,21 @@ export class HederaEngine extends CurrencyEngine< .build(this.client) const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount: `-${nativeAmount}`, + currencyCode, // currencyCode + date: 0, isSend: true, + nativeAmount: `-${nativeAmount}`, // UI shows the fee subtracted from the sent amount which doesn't make sense here networkFee, // networkFee - ourReceiveAddresses: [], // ourReceiveAddresses - signedTx: '', // signedTx otherParams: { fromAddress: this.walletLocalData.publicKey, toAddress: publicAddress, transferTx: base64.stringify(transferTx.toBytes()) }, + ourReceiveAddresses: [], // ourReceiveAddresses + signedTx: '', // signedTx + txid: '', walletId: this.walletId } return edgeTransaction diff --git a/src/polkadot/PolkadotEngine.ts b/src/polkadot/PolkadotEngine.ts index fbd611f73..5de60d221 100644 --- a/src/polkadot/PolkadotEngine.ts +++ b/src/polkadot/PolkadotEngine.ts @@ -189,15 +189,15 @@ export class PolkadotEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: hash, - date, - currencyCode: this.currencyInfo.currencyCode, blockHeight, - nativeAmount, + currencyCode: this.currencyInfo.currencyCode, + date, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee: fee, ourReceiveAddresses, signedTx: '', + txid: hash, walletId: this.walletId } this.addTransaction(this.currencyInfo.currencyCode, edgeTransaction) @@ -482,16 +482,16 @@ export class PolkadotEngine extends CurrencyEngine< // ********************************** // Create the unsigned EdgeTransaction const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount: mul(totalTxAmount, '-1'), + currencyCode, + date: 0, isSend: true, + nativeAmount: mul(totalTxAmount, '-1'), networkFee: nativeNetworkFee, + otherParams, ourReceiveAddresses: [], signedTx: '', - otherParams, + txid: '', walletId: this.walletId } diff --git a/src/ripple/RippleEngine.ts b/src/ripple/RippleEngine.ts index b0da04ec4..004ba7c64 100644 --- a/src/ripple/RippleEngine.ts +++ b/src/ripple/RippleEngine.ts @@ -166,19 +166,19 @@ export class XrpEngine extends CurrencyEngine< : this.allTokensMap[fromTokenId] const out: EdgeTransaction = { - txid: '', - date: Date.now() / 1000, - currencyCode, blockHeight: 0, // blockHeight, + currencyCode, + date: Date.now() / 1000, + isSend: true, metadata, nativeAmount: `-${add(fromNativeAmount, networkFee)}`, - isSend: true, networkFee, - ourReceiveAddresses: [], - signedTx: '', otherParams: { xrpTransaction }, + ourReceiveAddresses: [], + signedTx: '', + txid: '', walletId: this.walletId } return out @@ -337,16 +337,16 @@ export class XrpEngine extends CurrencyEngine< } // Parent currency like XRP this.addTransaction(currency, { - txid: hash.toLowerCase(), - date: rippleTimeToUnixTime(date) / 1000, // Returned date is in "ripple time" which is unix time if it had started on Jan 1 2000 - currencyCode: currency, blockHeight: tx.ledger_index ?? -1, - nativeAmount, + currencyCode: currency, + date: rippleTimeToUnixTime(date) / 1000, // Returned date is in "ripple time" which is unix time if it had started on Jan 1 2000 isSend, + nativeAmount, networkFee, + otherParams: {}, ourReceiveAddresses, signedTx: '', - otherParams: {}, + txid: hash.toLowerCase(), walletId: this.walletId }) } else { @@ -372,16 +372,16 @@ export class XrpEngine extends CurrencyEngine< } this.addTransaction(currencyCode, { - txid: hash.toLowerCase(), - date: rippleTimeToUnixTime(date) / 1000, // Returned date is in "ripple time" which is unix time if it had started on Jan 1 2000 - currencyCode, blockHeight: tx.ledger_index ?? -1, - nativeAmount, + currencyCode, + date: rippleTimeToUnixTime(date) / 1000, // Returned date is in "ripple time" which is unix time if it had started on Jan 1 2000 isSend, + nativeAmount, networkFee: '0', + otherParams: {}, ourReceiveAddresses, signedTx: '', - otherParams: {}, + txid: hash.toLowerCase(), walletId: this.walletId }) } @@ -628,19 +628,19 @@ export class XrpEngine extends CurrencyEngine< }) return { - txid: '', - date: Date.now() / 1000, - currencyCode: this.currencyInfo.currencyCode, blockHeight: 0, // blockHeight, + currencyCode: this.currencyInfo.currencyCode, + date: Date.now() / 1000, + isSend: true, metadata: edgeSpendInfo.metadata, nativeAmount: `-${networkFee}`, - isSend: true, networkFee, - ourReceiveAddresses: [], - signedTx: '', otherParams: { xrpTransaction }, + ourReceiveAddresses: [], + signedTx: '', + txid: '', walletId: this.walletId } } @@ -774,17 +774,17 @@ export class XrpEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: '', // txid - date: 0, // date - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount, // nativeAmount + currencyCode, // currencyCode + date: 0, // date isSend: true, + nativeAmount, // nativeAmount networkFee, - parentNetworkFee, + otherParams, ourReceiveAddresses: [], // ourReceiveAddresses + parentNetworkFee, signedTx: '', // signedTx - otherParams, + txid: '', // txid walletId: this.walletId } diff --git a/src/solana/SolanaEngine.ts b/src/solana/SolanaEngine.ts index 3f349e307..d5febdb82 100644 --- a/src/solana/SolanaEngine.ts +++ b/src/solana/SolanaEngine.ts @@ -176,15 +176,15 @@ export class SolanaEngine extends CurrencyEngine< ourReceiveAddresses.push(this.base58PublicKey) } const edgeTransaction: EdgeTransaction = { - txid: tx.transaction.signatures[0], - date: timestamp, - currencyCode: this.chainCode, blockHeight: tx.slot, - nativeAmount: amount.toString(), + currencyCode: this.chainCode, + date: timestamp, isSend: amount.toString().startsWith('-'), + nativeAmount: amount.toString(), networkFee: fee.toString(), ourReceiveAddresses, signedTx: '', + txid: tx.transaction.signatures[0], walletId: this.walletId } this.addTransaction(this.chainCode, edgeTransaction) @@ -374,16 +374,16 @@ export class SolanaEngine extends CurrencyEngine< // Create the unsigned EdgeTransaction const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount: mul(totalTxAmount, '-1'), + currencyCode, + date: 0, isSend: true, + nativeAmount: mul(totalTxAmount, '-1'), networkFee: nativeNetworkFee, + otherParams, ourReceiveAddresses: [], signedTx: '', - otherParams, + txid: '', walletId: this.walletId } diff --git a/src/stellar/StellarEngine.ts b/src/stellar/StellarEngine.ts index d5a3cc765..3b568cd07 100644 --- a/src/stellar/StellarEngine.ts +++ b/src/stellar/StellarEngine.ts @@ -249,20 +249,20 @@ export class StellarEngine extends CurrencyEngine< nativeAmount = '-' + nativeAmount } const edgeTransaction: EdgeTransaction = { - txid: tx.transaction_hash, - date, - currencyCode, blockHeight: rawTx.ledger_attr > 0 ? rawTx.ledger_attr : 0, // API shows no ledger number ?? - nativeAmount, + currencyCode, + date, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, - parentNetworkFee: '0', - ourReceiveAddresses, - signedTx: '', otherParams: { fromAddress, toAddress }, + ourReceiveAddresses, + parentNetworkFee: '0', + signedTx: '', + txid: tx.transaction_hash, walletId: this.walletId } @@ -555,20 +555,20 @@ export class StellarEngine extends CurrencyEngine< nativeAmount = `-${nativeAmount}` const idInternal = this.pendingTransactionsIndex const edgeTransaction: EdgeTransaction = { - txid: '', // txid - date: 0, // date - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount, // nativeAmount + currencyCode, // currencyCode + date: 0, // date isSend: nativeAmount.startsWith('-'), + nativeAmount, // nativeAmount networkFee, // networkFee - ourReceiveAddresses: [], // ourReceiveAddresses - signedTx: '', // signedTx otherParams: { idInternal, fromAddress: this.walletLocalData.publicKey, toAddress: publicAddress }, + ourReceiveAddresses: [], // ourReceiveAddresses + signedTx: '', // signedTx + txid: '', // txid walletId: this.walletId } this.pendingTransactionsMap[idInternal] = transaction diff --git a/src/tezos/TezosEngine.ts b/src/tezos/TezosEngine.ts index b899f765c..01f5fbaee 100644 --- a/src/tezos/TezosEngine.ts +++ b/src/tezos/TezosEngine.ts @@ -273,16 +273,16 @@ export class TezosEngine extends CurrencyEngine< nativeAmount = '-' + add(nativeAmount, networkFee) } const edgeTransaction: EdgeTransaction = { - txid: tx.hash, - date, - currencyCode, blockHeight, - nativeAmount, + currencyCode, + date, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, + otherParams: {}, ourReceiveAddresses, signedTx: '', - otherParams: {}, + txid: tx.hash, walletId: this.walletId } if (!failedOperation) { @@ -464,21 +464,21 @@ export class TezosEngine extends CurrencyEngine< nativeAmount = '-' + nativeAmount const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount, + currencyCode, + date: 0, isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee, - ourReceiveAddresses: [], - signedTx: '', otherParams: { idInternal: 0, fromAddress: this.walletLocalData.publicKey, toAddress: publicAddress, fullOp: ops }, + ourReceiveAddresses: [], + signedTx: '', + txid: '', walletId: this.walletId } return edgeTransaction diff --git a/src/tron/TronEngine.ts b/src/tron/TronEngine.ts index eacf54df5..66dcc331b 100644 --- a/src/tron/TronEngine.ts +++ b/src/tron/TronEngine.ts @@ -481,15 +481,15 @@ export class TronEngine extends CurrencyEngine { const { currencyCode } = this.currencyInfo const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode, blockHeight: blockNumber, - nativeAmount, + currencyCode, + date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee: feeNativeAmount, ourReceiveAddresses: ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -518,15 +518,15 @@ export class TronEngine extends CurrencyEngine { const { currencyCode } = this.currencyInfo const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode, blockHeight: blockNumber, - nativeAmount: mul(feeNativeAmount, '-1'), + currencyCode, + date: Math.floor(timestamp / 1000), isSend: true, + nativeAmount: mul(feeNativeAmount, '-1'), networkFee: feeNativeAmount, ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -554,15 +554,15 @@ export class TronEngine extends CurrencyEngine { const { currencyCode } = this.currencyInfo const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode, blockHeight: blockNumber, - nativeAmount: mul(nativeAmount, '-1'), + currencyCode, + date: Math.floor(timestamp / 1000), isSend: true, + nativeAmount: mul(nativeAmount, '-1'), networkFee: feeNativeAmount, ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -591,15 +591,15 @@ export class TronEngine extends CurrencyEngine { const nativeAmount = sub(unfreezeAmount.toString(), feeNativeAmount) const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode, blockHeight: blockNumber, - nativeAmount, + currencyCode, + date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee: feeNativeAmount, ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -627,15 +627,15 @@ export class TronEngine extends CurrencyEngine { const { currencyCode } = this.currencyInfo const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode, blockHeight: blockNumber, - nativeAmount: mul(nativeAmount, '-1'), + currencyCode, + date: Math.floor(timestamp / 1000), isSend: true, + nativeAmount: mul(nativeAmount, '-1'), networkFee: feeNativeAmount, ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -668,15 +668,15 @@ export class TronEngine extends CurrencyEngine { const nativeAmount = sub(unfreezeBalance.toString(), feeNativeAmount) const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode, blockHeight: blockNumber, - nativeAmount, + currencyCode, + date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee: feeNativeAmount, ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -740,15 +740,15 @@ export class TronEngine extends CurrencyEngine { } const edgeTransaction: EdgeTransaction = { - txid, - date: Math.floor(timestamp / 1000), - currencyCode: metaToken.currencyCode, blockHeight, - nativeAmount, + currencyCode: metaToken.currencyCode, + date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + nativeAmount, networkFee: '0', ourReceiveAddresses, signedTx: '', + txid, walletId: this.walletId } @@ -1106,20 +1106,20 @@ export class TronEngine extends CurrencyEngine { const networkFee = await this.calcTxFee({ unsignedTxHex: transactionHex }) const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode: this.currencyInfo.currencyCode, blockHeight: 0, - nativeAmount: stakedAmount.nativeAmount, + currencyCode: this.currencyInfo.currencyCode, + date: 0, isSend: stakedAmount.nativeAmount.startsWith('-'), + metadata: { + notes: resource + }, + nativeAmount: stakedAmount.nativeAmount, networkFee, + otherParams: txOtherParams, ourReceiveAddresses: [], signedTx: '', - otherParams: txOtherParams, - walletId: this.walletId, - metadata: { - notes: resource - } + txid: '', + walletId: this.walletId } return edgeTransaction @@ -1148,20 +1148,20 @@ export class TronEngine extends CurrencyEngine { const networkFee = await this.calcTxFee({ unsignedTxHex: transactionHex }) const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode: this.currencyInfo.currencyCode, blockHeight: 0, - nativeAmount: mul(nativeAmount, '-1'), + currencyCode: this.currencyInfo.currencyCode, + date: 0, isSend: true, + metadata: { + notes: resource + }, + nativeAmount: mul(nativeAmount, '-1'), networkFee, + otherParams: txOtherParams, ourReceiveAddresses: [], signedTx: '', - otherParams: txOtherParams, - walletId: this.walletId, - metadata: { - notes: resource - } + txid: '', + walletId: this.walletId } return edgeTransaction @@ -1195,20 +1195,20 @@ export class TronEngine extends CurrencyEngine { const networkFee = await this.calcTxFee({ unsignedTxHex: transactionHex }) const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode: this.currencyInfo.currencyCode, blockHeight: 0, - nativeAmount: stakedAmount.nativeAmount, + currencyCode: this.currencyInfo.currencyCode, + date: 0, isSend: stakedAmount.nativeAmount.startsWith('-'), + metadata: { + notes: resource + }, + nativeAmount: stakedAmount.nativeAmount, networkFee, + otherParams: txOtherParams, ourReceiveAddresses: [], signedTx: '', - otherParams: txOtherParams, - walletId: this.walletId, - metadata: { - notes: resource - } + txid: '', + walletId: this.walletId } return edgeTransaction @@ -1422,16 +1422,16 @@ export class TronEngine extends CurrencyEngine { // ********************************** // Create the unsigned EdgeTransaction const edgeTransaction: EdgeTransaction = { - txid: '', // txid - date: 0, // date - currencyCode, // currencyCode blockHeight: 0, // blockHeight - nativeAmount: mul(edgeNativeAmount, '-1'), // nativeAmount + currencyCode, // currencyCode + date: 0, // date isSend: true, + nativeAmount: mul(edgeNativeAmount, '-1'), // nativeAmount networkFee, // networkFee + otherParams: txOtherParams, // otherParams ourReceiveAddresses: [], // ourReceiveAddresses signedTx: '', // signedTx - otherParams: txOtherParams, // otherParams + txid: '', // txid walletId: this.walletId } diff --git a/src/zcash/ZcashEngine.ts b/src/zcash/ZcashEngine.ts index 417de7b5a..638fbc8b4 100644 --- a/src/zcash/ZcashEngine.ts +++ b/src/zcash/ZcashEngine.ts @@ -255,16 +255,16 @@ export class ZcashEngine extends CurrencyEngine< } const edgeTransaction: EdgeTransaction = { - txid: tx.rawTransactionId, - date: tx.blockTimeInSeconds, - currencyCode: this.currencyInfo.currencyCode, blockHeight: tx.minedHeight, - nativeAmount: netNativeAmount, + currencyCode: this.currencyInfo.currencyCode, + date: tx.blockTimeInSeconds, isSend: netNativeAmount.startsWith('-'), + nativeAmount: netNativeAmount, networkFee: this.networkInfo.defaultNetworkFee, + otherParams: {}, ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction signedTx: '', - otherParams: {}, + txid: tx.rawTransactionId, walletId: this.walletId } this.addTransaction(this.currencyInfo.currencyCode, edgeTransaction) @@ -333,15 +333,15 @@ export class ZcashEngine extends CurrencyEngine< const txNativeAmount = mul(totalTxAmount, '-1') const edgeTransaction: EdgeTransaction = { - txid: '', - date: 0, - currencyCode, blockHeight: 0, - nativeAmount: txNativeAmount, + currencyCode, + date: 0, isSend: true, + nativeAmount: txNativeAmount, networkFee: this.networkInfo.defaultNetworkFee, ourReceiveAddresses: [], signedTx: '', + txid: '', walletId: this.walletId } diff --git a/test/tezos/engine.test.ts b/test/tezos/engine.test.ts index f0be09f1d..4fd16e9d4 100644 --- a/test/tezos/engine.test.ts +++ b/test/tezos/engine.test.ts @@ -148,15 +148,12 @@ describe(`Tezos engine`, function () { }) it('should sign a transaction', async function () { edgeTransaction = { - txid: '', - date: 0, - currencyCode: 'XTZ', blockHeight: 0, - nativeAmount: '-3002650', + currencyCode: 'XTZ', + date: 0, isSend: true, + nativeAmount: '-3002650', networkFee: '2650', - ourReceiveAddresses: ['tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9'], - signedTx: '', otherParams: { idInternal: 0, fromAddress: 'tz1TC6ETpRC1awG3Sq226TgMx4wHbJRTzod6', @@ -192,6 +189,9 @@ describe(`Tezos engine`, function () { } } }, + ourReceiveAddresses: ['tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9'], + signedTx: '', + txid: '', walletId: '' } const signedOpBytes = From 159cb94ffe8efd7c7456bed5b9a703f3a7b33642 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Mon, 11 Sep 2023 16:31:56 -0700 Subject: [PATCH 3/8] Upgrade to edge-core-js v1.6.0 --- package.json | 2 +- src/algorand/AlgorandEngine.ts | 2 ++ src/binance/BinanceEngine.ts | 2 ++ src/eos/EosEngine.ts | 4 ++++ src/ethereum/EthereumEngine.ts | 1 + src/ethereum/EthereumNetwork.ts | 2 ++ src/filecoin/FilecoinEngine.ts | 3 +++ src/fio/FioEngine.ts | 3 +++ src/hedera/HederaEngine.ts | 2 ++ src/polkadot/PolkadotEngine.ts | 2 ++ src/ripple/RippleEngine.ts | 5 ++++ src/solana/SolanaEngine.ts | 2 ++ src/stellar/StellarEngine.ts | 2 ++ src/tezos/TezosEngine.ts | 2 ++ src/tron/TronEngine.ts | 11 +++++++++ src/zcash/ZcashEngine.ts | 2 ++ test/tezos/engine.test.ts | 1 + yarn.lock | 42 +++++++++++++-------------------- 18 files changed, 63 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index fac158f22..e467e92e9 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,7 @@ "babel-eslint": "^10.1.0", "chai": "^4.2.0", "crypto-browserify": "^3.12.0", - "edge-core-js": "^1.3.7", + "edge-core-js": "^1.6.0", "esbuild-loader": "^2.20.0", "eslint": "^7.14.0", "eslint-config-standard-kit": "0.15.1", diff --git a/src/algorand/AlgorandEngine.ts b/src/algorand/AlgorandEngine.ts index 712f56bd7..75ab696a2 100644 --- a/src/algorand/AlgorandEngine.ts +++ b/src/algorand/AlgorandEngine.ts @@ -335,6 +335,7 @@ export class AlgorandEngine extends CurrencyEngine< currencyCode, date: roundTime, isSend, + memos: [], nativeAmount, networkFee, ourReceiveAddresses, @@ -627,6 +628,7 @@ export class AlgorandEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, + memos: [], nativeAmount, networkFee, otherParams, diff --git a/src/binance/BinanceEngine.ts b/src/binance/BinanceEngine.ts index 3ce7a150d..979bb46dd 100644 --- a/src/binance/BinanceEngine.ts +++ b/src/binance/BinanceEngine.ts @@ -187,6 +187,7 @@ export class BinanceEngine extends CurrencyEngine< currencyCode, date: unixTimestamp, isSend: netNativeAmount.startsWith('-'), + memos: [], metadata: { notes: tx.memo }, @@ -436,6 +437,7 @@ export class BinanceEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, // date isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, // nativeAmount networkFee: nativeNetworkFee, // networkFee, supposedly fixed otherParams, // otherParams diff --git a/src/eos/EosEngine.ts b/src/eos/EosEngine.ts index a8355a07d..a0d67c4dd 100644 --- a/src/eos/EosEngine.ts +++ b/src/eos/EosEngine.ts @@ -262,6 +262,7 @@ export class EosEngine extends CurrencyEngine { currencyCode, date: Date.parse(blockTime) / 1000, isSend: nativeAmount.startsWith('-'), + memos: [], metadata: { name, notes: memo @@ -343,6 +344,7 @@ export class EosEngine extends CurrencyEngine { currencyCode, date, isSend: nativeAmount.startsWith('-'), + memos: [], metadata: { notes: memo }, @@ -874,6 +876,7 @@ export class EosEngine extends CurrencyEngine { currencyCode: this.currencyInfo.currencyCode, date: 0, isSend: true, + memos: [], nativeAmount: '-3', networkFee: '0', otherParams: { @@ -1045,6 +1048,7 @@ export class EosEngine extends CurrencyEngine { currencyCode, // currencyCode date: 0, // date isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, // nativeAmount networkFee, // networkFee otherParams: { diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index ea85c864c..4768491fc 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -1025,6 +1025,7 @@ export class EthereumEngine extends CurrencyEngine< date: 0, // date feeRateUsed: getFeeRateUsed(miningFees.gasPrice, otherParams.gas), isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, // nativeAmount networkFee: nativeNetworkFee, // networkFee otherParams, // otherParams diff --git a/src/ethereum/EthereumNetwork.ts b/src/ethereum/EthereumNetwork.ts index a6fa98435..b383dc16c 100644 --- a/src/ethereum/EthereumNetwork.ts +++ b/src/ethereum/EthereumNetwork.ts @@ -352,6 +352,7 @@ export class EthereumNetwork { ? getFeeRateUsed(gasPrice, tx.gas, tx.gasUsed) : undefined, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams, @@ -444,6 +445,7 @@ export class EthereumNetwork { currencyCode, date: tokenTransfer.attributes.blockCreationTime, isSend: netNativeAmount.startsWith('-'), + memos: [], nativeAmount: netNativeAmount, networkFee, otherParams, diff --git a/src/filecoin/FilecoinEngine.ts b/src/filecoin/FilecoinEngine.ts index 3d3975e30..971bd1fec 100644 --- a/src/filecoin/FilecoinEngine.ts +++ b/src/filecoin/FilecoinEngine.ts @@ -196,6 +196,7 @@ export class FilecoinEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, + memos: [], nativeAmount: txNativeAmount, networkFee, otherParams, @@ -477,6 +478,7 @@ export class FilecoinEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, date: messageDetails.timestamp, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams: {}, @@ -513,6 +515,7 @@ export class FilecoinEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, date: message.block_time, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams: {}, diff --git a/src/fio/FioEngine.ts b/src/fio/FioEngine.ts index 66f847905..946e6fa66 100644 --- a/src/fio/FioEngine.ts +++ b/src/fio/FioEngine.ts @@ -487,6 +487,7 @@ export class FioEngine extends CurrencyEngine { currencyCode, date: this.getUTCDate(action.block_time) / 1000, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams, @@ -574,6 +575,7 @@ export class FioEngine extends CurrencyEngine { currencyCode, date: this.getUTCDate(action.block_time) / 1000, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams, @@ -1682,6 +1684,7 @@ export class FioEngine extends CurrencyEngine { currencyCode, date: 0, isSend: true, + memos: [], nativeAmount: sub(`-${quantity}`, `${fee}`), networkFee: `${fee}`, otherParams: { diff --git a/src/hedera/HederaEngine.ts b/src/hedera/HederaEngine.ts index f60f2c015..96f4bacc1 100644 --- a/src/hedera/HederaEngine.ts +++ b/src/hedera/HederaEngine.ts @@ -369,6 +369,7 @@ export class HederaEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, // currencyCode date: parseInt(tx.valid_start_timestamp), isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee: tx.charged_tx_fee.toString(), // networkFee otherParams: { @@ -463,6 +464,7 @@ export class HederaEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, isSend: true, + memos: [], nativeAmount: `-${nativeAmount}`, // UI shows the fee subtracted from the sent amount which doesn't make sense here networkFee, // networkFee diff --git a/src/polkadot/PolkadotEngine.ts b/src/polkadot/PolkadotEngine.ts index 5de60d221..d07751ffc 100644 --- a/src/polkadot/PolkadotEngine.ts +++ b/src/polkadot/PolkadotEngine.ts @@ -193,6 +193,7 @@ export class PolkadotEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, date, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee: fee, ourReceiveAddresses, @@ -486,6 +487,7 @@ export class PolkadotEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, + memos: [], nativeAmount: mul(totalTxAmount, '-1'), networkFee: nativeNetworkFee, otherParams, diff --git a/src/ripple/RippleEngine.ts b/src/ripple/RippleEngine.ts index 004ba7c64..eee216d0c 100644 --- a/src/ripple/RippleEngine.ts +++ b/src/ripple/RippleEngine.ts @@ -170,6 +170,7 @@ export class XrpEngine extends CurrencyEngine< currencyCode, date: Date.now() / 1000, isSend: true, + memos: [], metadata, nativeAmount: `-${add(fromNativeAmount, networkFee)}`, networkFee, @@ -341,6 +342,7 @@ export class XrpEngine extends CurrencyEngine< currencyCode: currency, date: rippleTimeToUnixTime(date) / 1000, // Returned date is in "ripple time" which is unix time if it had started on Jan 1 2000 isSend, + memos: [], nativeAmount, networkFee, otherParams: {}, @@ -376,6 +378,7 @@ export class XrpEngine extends CurrencyEngine< currencyCode, date: rippleTimeToUnixTime(date) / 1000, // Returned date is in "ripple time" which is unix time if it had started on Jan 1 2000 isSend, + memos: [], nativeAmount, networkFee: '0', otherParams: {}, @@ -632,6 +635,7 @@ export class XrpEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, date: Date.now() / 1000, isSend: true, + memos: [], metadata: edgeSpendInfo.metadata, nativeAmount: `-${networkFee}`, networkFee, @@ -778,6 +782,7 @@ export class XrpEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, // date isSend: true, + memos: [], nativeAmount, // nativeAmount networkFee, otherParams, diff --git a/src/solana/SolanaEngine.ts b/src/solana/SolanaEngine.ts index d5febdb82..8451b70c9 100644 --- a/src/solana/SolanaEngine.ts +++ b/src/solana/SolanaEngine.ts @@ -180,6 +180,7 @@ export class SolanaEngine extends CurrencyEngine< currencyCode: this.chainCode, date: timestamp, isSend: amount.toString().startsWith('-'), + memos: [], nativeAmount: amount.toString(), networkFee: fee.toString(), ourReceiveAddresses, @@ -378,6 +379,7 @@ export class SolanaEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, + memos: [], nativeAmount: mul(totalTxAmount, '-1'), networkFee: nativeNetworkFee, otherParams, diff --git a/src/stellar/StellarEngine.ts b/src/stellar/StellarEngine.ts index 3b568cd07..3bdf90efc 100644 --- a/src/stellar/StellarEngine.ts +++ b/src/stellar/StellarEngine.ts @@ -253,6 +253,7 @@ export class StellarEngine extends CurrencyEngine< currencyCode, date, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams: { @@ -559,6 +560,7 @@ export class StellarEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, // date isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, // nativeAmount networkFee, // networkFee otherParams: { diff --git a/src/tezos/TezosEngine.ts b/src/tezos/TezosEngine.ts index 01f5fbaee..2a73d208c 100644 --- a/src/tezos/TezosEngine.ts +++ b/src/tezos/TezosEngine.ts @@ -277,6 +277,7 @@ export class TezosEngine extends CurrencyEngine< currencyCode, date, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams: {}, @@ -468,6 +469,7 @@ export class TezosEngine extends CurrencyEngine< currencyCode, date: 0, isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee, otherParams: { diff --git a/src/tron/TronEngine.ts b/src/tron/TronEngine.ts index 66dcc331b..f9b6b24f1 100644 --- a/src/tron/TronEngine.ts +++ b/src/tron/TronEngine.ts @@ -485,6 +485,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee: feeNativeAmount, ourReceiveAddresses: ourReceiveAddresses, @@ -522,6 +523,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, date: Math.floor(timestamp / 1000), isSend: true, + memos: [], nativeAmount: mul(feeNativeAmount, '-1'), networkFee: feeNativeAmount, ourReceiveAddresses, @@ -558,6 +560,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, date: Math.floor(timestamp / 1000), isSend: true, + memos: [], nativeAmount: mul(nativeAmount, '-1'), networkFee: feeNativeAmount, ourReceiveAddresses, @@ -595,6 +598,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee: feeNativeAmount, ourReceiveAddresses, @@ -630,6 +634,7 @@ export class TronEngine extends CurrencyEngine { blockHeight: blockNumber, currencyCode, date: Math.floor(timestamp / 1000), + memos: [], isSend: true, nativeAmount: mul(nativeAmount, '-1'), networkFee: feeNativeAmount, @@ -672,6 +677,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee: feeNativeAmount, ourReceiveAddresses, @@ -744,6 +750,7 @@ export class TronEngine extends CurrencyEngine { currencyCode: metaToken.currencyCode, date: Math.floor(timestamp / 1000), isSend: nativeAmount.startsWith('-'), + memos: [], nativeAmount, networkFee: '0', ourReceiveAddresses, @@ -1110,6 +1117,7 @@ export class TronEngine extends CurrencyEngine { currencyCode: this.currencyInfo.currencyCode, date: 0, isSend: stakedAmount.nativeAmount.startsWith('-'), + memos: [], metadata: { notes: resource }, @@ -1152,6 +1160,7 @@ export class TronEngine extends CurrencyEngine { currencyCode: this.currencyInfo.currencyCode, date: 0, isSend: true, + memos: [], metadata: { notes: resource }, @@ -1199,6 +1208,7 @@ export class TronEngine extends CurrencyEngine { currencyCode: this.currencyInfo.currencyCode, date: 0, isSend: stakedAmount.nativeAmount.startsWith('-'), + memos: [], metadata: { notes: resource }, @@ -1426,6 +1436,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, // currencyCode date: 0, // date isSend: true, + memos: [], nativeAmount: mul(edgeNativeAmount, '-1'), // nativeAmount networkFee, // networkFee otherParams: txOtherParams, // otherParams diff --git a/src/zcash/ZcashEngine.ts b/src/zcash/ZcashEngine.ts index 638fbc8b4..6bbfe4961 100644 --- a/src/zcash/ZcashEngine.ts +++ b/src/zcash/ZcashEngine.ts @@ -259,6 +259,7 @@ export class ZcashEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, date: tx.blockTimeInSeconds, isSend: netNativeAmount.startsWith('-'), + memos: [], nativeAmount: netNativeAmount, networkFee: this.networkInfo.defaultNetworkFee, otherParams: {}, @@ -337,6 +338,7 @@ export class ZcashEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, + memos: [], nativeAmount: txNativeAmount, networkFee: this.networkInfo.defaultNetworkFee, ourReceiveAddresses: [], diff --git a/test/tezos/engine.test.ts b/test/tezos/engine.test.ts index 4fd16e9d4..7db3bc256 100644 --- a/test/tezos/engine.test.ts +++ b/test/tezos/engine.test.ts @@ -152,6 +152,7 @@ describe(`Tezos engine`, function () { currencyCode: 'XTZ', date: 0, isSend: true, + memos: [], nativeAmount: '-3002650', networkFee: '2650', otherParams: { diff --git a/yarn.lock b/yarn.lock index cef35f7d7..3e5339a88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3471,10 +3471,10 @@ ed25519@0.0.4: bindings "^1.2.1" nan "^2.0.9" -edge-core-js@^1.3.7: - version "1.3.7" - resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-1.3.7.tgz#2f31bb92332593c045d7894843fd7deb7aa411f3" - integrity sha512-hHCkJciJpcSRPzSbPKc2CS/Ngjd6PuST4PhR9Uaz9b1TyVr522qYKndQzKsgDeGP/QNnyV35OWbpghMK6a4WTA== +edge-core-js@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-1.6.0.tgz#3a381faa3a483f631b3380e00615a22b2004ed52" + integrity sha512-y6nfz49ALKmsnyAkjBn5s5UNS7hEU3PhtPEoXDo6sOVgidEplcMMwUa5vEw15qcZnTxYmvgDCaNbj2UAxzlhxg== dependencies: aes-js "^3.1.0" base-x "^4.0.0" @@ -3482,7 +3482,7 @@ edge-core-js@^1.3.7: cleaners "^0.3.14" currency-codes "^1.1.2" disklet "^0.5.2" - edge-sync-client "^0.2.7" + edge-sync-client "^0.2.8" elliptic "^6.4.0" hash.js "^1.1.7" hmac-drbg "^1.0.1" @@ -3493,13 +3493,13 @@ edge-core-js@^1.3.7: rfc4648 "^1.4.0" scrypt-js "^2.0.3" serverlet "^0.1.2" - yaob "^0.3.9" + yaob "^0.3.11" yavent "^0.1.3" -edge-sync-client@^0.2.7: - version "0.2.7" - resolved "https://registry.yarnpkg.com/edge-sync-client/-/edge-sync-client-0.2.7.tgz#57041f1a17565f24750803a99aaea517361fe9e1" - integrity sha512-ySWvsvHisg3e5gV/KBQymt0Fos1Nqupb6fbvxn5YXM5SmsOWz2iGRqocSc/Qxyd85WV7G/DjpJ8zWVqf0eUTrg== +edge-sync-client@^0.2.8: + version "0.2.8" + resolved "https://registry.yarnpkg.com/edge-sync-client/-/edge-sync-client-0.2.8.tgz#150c9d97676b5ddd158efd38565de1be29e525bc" + integrity sha512-5iaVYvws4fEk9gSkijo98nh46wyT2D0YSAYzwAyM4v/oHu+tVa18WrdGC+aP4HZVcrsg/LzrLu/NX9JyTsW9Cw== dependencies: base-x "^1.0.4" cleaners "^0.3.9" @@ -7786,12 +7786,7 @@ tslib@^1.8.1, tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.0.3, tslib@^2.1.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" - integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg== - -tslib@^2.5.0, tslib@^2.5.3: +tslib@^2.0.3, tslib@^2.1.0, tslib@^2.5.0, tslib@^2.5.3: version "2.5.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.3.tgz#24944ba2d990940e6e982c4bea147aba80209913" integrity sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w== @@ -8331,16 +8326,11 @@ ws@^7.4.5: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.6.tgz#e59fc509fb15ddfb65487ee9765c5a51dec5fe7b" integrity sha512-6GLgCqo2cy2A2rjCNFlxQS6ZljG/coZfZXclldI8FB/1G3CCI36Zd8xy2HrFVACi8tfk5XrgLQEk+P0Tnz9UcA== -ws@^8.13.0: +ws@^8.13.0, ws@^8.2.2, ws@^8.4.2, ws@^8.8.1: version "8.13.0" resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== -ws@^8.2.2, ws@^8.4.2, ws@^8.8.1: - version "8.11.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.11.0.tgz#6a0d36b8edfd9f96d8b25683db2f8d7de6e8e143" - integrity sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg== - xhr2@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/xhr2/-/xhr2-0.1.4.tgz#7f87658847716db5026323812f818cadab387a5f" @@ -8391,10 +8381,10 @@ yaml@^1.10.0, yaml@^1.10.2: resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b" integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg== -yaob@^0.3.6, yaob@^0.3.9: - version "0.3.10" - resolved "https://registry.yarnpkg.com/yaob/-/yaob-0.3.10.tgz#fb86d54d564ff6014f6f52fafc4219b6c068f613" - integrity sha512-QU+03xtNssGOw01Tten5zlfNcrsMPQjy0Nr/gueVEbXYsXHgYeDKXNLgPNMdYdTY7qkvLj8IGLOk/MKtsUh+Fg== +yaob@^0.3.11, yaob@^0.3.6: + version "0.3.11" + resolved "https://registry.yarnpkg.com/yaob/-/yaob-0.3.11.tgz#54dc4e03f5edabf7a0701c57e73e97cc69d2fc42" + integrity sha512-RRMKxWsjMGF9X7fyPny0w3icGriQCCT7FMtNrmxxyjxQIQn8GB4+CT4SWpgUca82RBvjRt5pRqKmbnvmMfKc9A== dependencies: rfc4648 "^1.1.0" From 49a095f4addeaef9f31264fd4fab113820ea657e Mon Sep 17 00:00:00 2001 From: William Swanson Date: Fri, 18 Aug 2023 09:35:01 -0700 Subject: [PATCH 4/8] Reorganize currency infos We want to put the deprecated things in one place. --- src/algorand/algorandInfo.ts | 12 ++++----- src/algorand/algorandTestnetInfo.ts | 12 ++++----- src/binance/binanceInfo.ts | 13 +++++----- src/eos/info/eosInfo.ts | 30 ++++++++++------------ src/eos/info/telosInfo.ts | 28 ++++++++++---------- src/eos/info/waxInfo.ts | 29 ++++++++++----------- src/ethereum/info/avalancheInfo.ts | 14 +++++----- src/ethereum/info/binancesmartchainInfo.ts | 14 +++++----- src/ethereum/info/celoInfo.ts | 14 +++++----- src/ethereum/info/ethDevInfo.ts | 14 +++++----- src/ethereum/info/ethereumInfo.ts | 14 +++++----- src/ethereum/info/ethereumclassicInfo.ts | 14 +++++----- src/ethereum/info/ethereumpowInfo.ts | 14 +++++----- src/ethereum/info/fantomInfo.ts | 14 +++++----- src/ethereum/info/goerliInfo.ts | 14 +++++----- src/ethereum/info/kovanInfo.ts | 14 +++++----- src/ethereum/info/optimismInfo.ts | 14 +++++----- src/ethereum/info/polygonInfo.ts | 14 +++++----- src/ethereum/info/pulsechainInfo.ts | 14 +++++----- src/ethereum/info/rinkebyInfo.ts | 14 +++++----- src/ethereum/info/ropstenInfo.ts | 14 +++++----- src/ethereum/info/rskInfo.ts | 14 +++++----- src/ethereum/info/zksyncInfo.ts | 14 +++++----- src/filecoin/filecoinInfo.ts | 12 ++++----- src/fio/fioInfo.ts | 11 ++++---- src/hedera/hederaInfo.ts | 15 +++++------ src/hedera/hederaTestnetInfo.ts | 12 ++++----- src/polkadot/info/liberlandInfo.ts | 5 ++-- src/polkadot/info/liberlandTestnetInfo.ts | 5 ++-- src/polkadot/info/polkadotInfo.ts | 10 ++++---- src/ripple/rippleInfo.ts | 15 +++++------ src/solana/solanaInfo.ts | 10 ++++---- src/stellar/stellarInfo.ts | 13 +++++----- src/tezos/tezosInfo.ts | 10 ++++---- src/tron/tronInfo.ts | 12 ++++----- src/zcash/piratechainInfo.ts | 11 ++++---- src/zcash/zcashInfo.ts | 12 ++++----- 37 files changed, 246 insertions(+), 269 deletions(-) diff --git a/src/algorand/algorandInfo.ts b/src/algorand/algorandInfo.ts index d6f0c1cda..f61d68e4f 100644 --- a/src/algorand/algorandInfo.ts +++ b/src/algorand/algorandInfo.ts @@ -33,21 +33,16 @@ const networkInfo: AlgorandNetworkInfo = { } const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'ALGO', displayName: 'Algorand', pluginId: 'algorand', walletType: 'wallet:algorand', - defaultSettings: { customFeeSettings: ['fee'] }, - - memoType: 'text', - + // Explorers: addressExplorer: 'https://algoexplorer.io/address/%s', transactionExplorer: 'https://algoexplorer.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ALGO', multiplier: '1000000', @@ -55,7 +50,10 @@ const currencyInfo: EdgeCurrencyInfo = { } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + // Deprecated: + defaultSettings: { customFeeSettings: ['fee'] }, + memoType: 'text', + metaTokens: makeMetaTokens(builtinTokens) } export const algorand = makeOuterPlugin({ diff --git a/src/algorand/algorandTestnetInfo.ts b/src/algorand/algorandTestnetInfo.ts index 923c5cd4c..8e699680a 100644 --- a/src/algorand/algorandTestnetInfo.ts +++ b/src/algorand/algorandTestnetInfo.ts @@ -26,21 +26,16 @@ const networkInfo: AlgorandNetworkInfo = { } const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'ALGO', displayName: 'Algorand Testnet', pluginId: 'algorandtestnet', walletType: 'wallet:algorandtestnet', - defaultSettings: { customFeeSettings: ['fee'] }, - - memoType: 'text', - + // Explorers: addressExplorer: 'https://testnet.algoexplorer.io/address/%s', transactionExplorer: 'https://testnet.algoexplorer.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ALGO', multiplier: '1000000', @@ -48,7 +43,10 @@ const currencyInfo: EdgeCurrencyInfo = { } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + // Deprecated: + defaultSettings: { customFeeSettings: ['fee'] }, + memoType: 'text', + metaTokens: makeMetaTokens(builtinTokens) } export const algorandtestnet = makeOuterPlugin< diff --git a/src/binance/binanceInfo.ts b/src/binance/binanceInfo.ts index e299a972b..be15349f4 100644 --- a/src/binance/binanceInfo.ts +++ b/src/binance/binanceInfo.ts @@ -15,29 +15,28 @@ const networkInfo: BinanceNetworkInfo = { } const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'BNB', displayName: 'BNB Beacon Chain', pluginId: 'binance', walletType: 'wallet:binance', - defaultSettings: {}, - - memoMaxLength: 128, - + // Explorers: addressExplorer: 'https://explorer.binance.org/address/%s', transactionExplorer: 'https://explorer.binance.org/tx/%s', blockExplorer: 'https://explorer.binance.org/block/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'BNB', multiplier: '100000000', symbol: 'B' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + memoMaxLength: 128, + metaTokens: [] } export const binance = makeOuterPlugin({ diff --git a/src/eos/info/eosInfo.ts b/src/eos/info/eosInfo.ts index 1cf2fd154..47c4fff8d 100644 --- a/src/eos/info/eosInfo.ts +++ b/src/eos/info/eosInfo.ts @@ -27,33 +27,29 @@ export const eosNetworkInfo: EosNetworkInfo = { uriProtocol: 'eos' } -const denominations = [ - // An array of Objects of the possible denominations for this currency - { - name: 'EOS', - multiplier: '10000', - symbol: 'E' - } -] - export const eosCurrencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'EOS', displayName: 'EOS', pluginId: 'eos', + unsafeBroadcastTx: true, walletType: 'wallet:eos', - defaultSettings: {}, - - memoMaxLength: 256, - + // Explorers: addressExplorer: 'https://bloks.io/account/%s', transactionExplorer: 'https://bloks.io/transaction/%s', - denominations, - metaTokens: [], // Deprecated + denominations: [ + { + name: 'EOS', + multiplier: '10000', + symbol: 'E' + } + ], - unsafeBroadcastTx: true + // Deprecated: + defaultSettings: {}, + memoMaxLength: 256, + metaTokens: [] } export const eos = makeOuterPlugin({ diff --git a/src/eos/info/telosInfo.ts b/src/eos/info/telosInfo.ts index d40e2ddde..94a92561e 100644 --- a/src/eos/info/telosInfo.ts +++ b/src/eos/info/telosInfo.ts @@ -20,30 +20,28 @@ export const telosNetworkInfo: EosNetworkInfo = { uriProtocol: 'telos' } -const denominations = [ - { - name: 'TLOS', - multiplier: '10000', - symbol: 'T' - } -] - export const telosCurrencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'TLOS', displayName: 'Telos', pluginId: 'telos', walletType: 'wallet:telos', - defaultSettings: {}, - - memoMaxLength: 256, - + // Explorers: addressExplorer: 'https://telos.bloks.io/account/%s', transactionExplorer: 'https://telos.bloks.io/transaction/%s', - denominations, - metaTokens: [] // Deprecated + denominations: [ + { + name: 'TLOS', + multiplier: '10000', + symbol: 'T' + } + ], + + // Deprecated: + defaultSettings: {}, + memoMaxLength: 256, + metaTokens: [] } export const telos = makeOuterPlugin({ diff --git a/src/eos/info/waxInfo.ts b/src/eos/info/waxInfo.ts index eb42ddccc..ec3747161 100644 --- a/src/eos/info/waxInfo.ts +++ b/src/eos/info/waxInfo.ts @@ -16,31 +16,28 @@ export const waxNetworkInfo: EosNetworkInfo = { uriProtocol: 'wax' } -const denominations = [ - // An array of Objects of the possible denominations for this currency - { - name: 'WAX', - multiplier: '100000000', - symbol: 'W' - } -] - export const waxCurrencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'WAX', displayName: 'Wax', pluginId: 'wax', walletType: 'wallet:wax', - defaultSettings: {}, - - memoMaxLength: 256, - + // Explorers: addressExplorer: 'https://wax.bloks.io/account/%s', transactionExplorer: 'https://wax.bloks.io/transaction/%s', - denominations, - metaTokens: [] // Deprecated + denominations: [ + { + name: 'WAX', + multiplier: '100000000', + symbol: 'W' + } + ], + + // Deprecated: + defaultSettings: {}, + memoMaxLength: 256, + metaTokens: [] } export const wax = makeOuterPlugin({ diff --git a/src/ethereum/info/avalancheInfo.ts b/src/ethereum/info/avalancheInfo.ts index cfe69babf..c0a5581be 100644 --- a/src/ethereum/info/avalancheInfo.ts +++ b/src/ethereum/info/avalancheInfo.ts @@ -207,28 +207,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'AVAX', displayName: 'Avalanche', pluginId: 'avalanche', // matching mnemonic here walletType: 'wallet:avalanche', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://snowtrace.io/address/%s', transactionExplorer: 'https://snowtrace.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'AVAX', multiplier: '1000000000000000000', symbol: 'AVAX' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const avalanche = makeOuterPlugin({ diff --git a/src/ethereum/info/binancesmartchainInfo.ts b/src/ethereum/info/binancesmartchainInfo.ts index 54fc69134..f3677e1f7 100644 --- a/src/ethereum/info/binancesmartchainInfo.ts +++ b/src/ethereum/info/binancesmartchainInfo.ts @@ -82,28 +82,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'BNB', displayName: 'BNB Smart Chain', pluginId: 'binancesmartchain', walletType: 'wallet:binancesmartchain', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://bscscan.com/address/%s', transactionExplorer: 'https://bscscan.com/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'BNB', multiplier: '1000000000000000000', symbol: 'BNB' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const binancesmartchain = makeOuterPlugin< diff --git a/src/ethereum/info/celoInfo.ts b/src/ethereum/info/celoInfo.ts index 7885220a4..971f570b0 100644 --- a/src/ethereum/info/celoInfo.ts +++ b/src/ethereum/info/celoInfo.ts @@ -87,28 +87,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'CELO', displayName: 'Celo', pluginId: 'celo', walletType: 'wallet:celo', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://explorer.celo.org/address/%s', transactionExplorer: 'https://explorer.celo.org/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'CELO', multiplier: '1000000000000000000', symbol: 'CELO' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const celo = makeOuterPlugin({ diff --git a/src/ethereum/info/ethDevInfo.ts b/src/ethereum/info/ethDevInfo.ts index 0a13b1e41..00214c07a 100644 --- a/src/ethereum/info/ethDevInfo.ts +++ b/src/ethereum/info/ethDevInfo.ts @@ -130,21 +130,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ETH', displayName: 'Dev Ethereum', pluginId: 'ethDev', walletType: 'wallet:ethDev', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://etherscan.io/address/%s', transactionExplorer: 'https://etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ETH', multiplier: '1000000000000000000', @@ -156,7 +152,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mΞ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const ethDev = makeOuterPlugin({ diff --git a/src/ethereum/info/ethereumInfo.ts b/src/ethereum/info/ethereumInfo.ts index 9d459635a..32f4b88c7 100644 --- a/src/ethereum/info/ethereumInfo.ts +++ b/src/ethereum/info/ethereumInfo.ts @@ -1112,21 +1112,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ETH', displayName: 'Ethereum', pluginId: 'ethereum', walletType: 'wallet:ethereum', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://etherscan.io/address/%s', transactionExplorer: 'https://etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ETH', multiplier: '1000000000000000000', @@ -1138,7 +1134,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mΞ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const ethereum = makeOuterPlugin({ diff --git a/src/ethereum/info/ethereumclassicInfo.ts b/src/ethereum/info/ethereumclassicInfo.ts index 6e609f5e2..74af5450a 100644 --- a/src/ethereum/info/ethereumclassicInfo.ts +++ b/src/ethereum/info/ethereumclassicInfo.ts @@ -97,21 +97,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ETC', displayName: 'Ethereum Classic', pluginId: 'ethereumclassic', walletType: 'wallet:ethereumclassic', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://blockscout.com/etc/mainnet/address/%s', transactionExplorer: 'https://blockscout.com/etc/mainnet/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ETC', multiplier: '1000000000000000000', @@ -123,7 +119,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mΞ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const ethereumclassic = makeOuterPlugin< diff --git a/src/ethereum/info/ethereumpowInfo.ts b/src/ethereum/info/ethereumpowInfo.ts index 4423d0342..5a67b71ff 100644 --- a/src/ethereum/info/ethereumpowInfo.ts +++ b/src/ethereum/info/ethereumpowInfo.ts @@ -78,21 +78,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ETHW', displayName: 'EthereumPoW', pluginId: 'ethereumpow', walletType: 'wallet:ethereumpow', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://www.oklink.com/en/ethw/address/%s', transactionExplorer: 'https://www.oklink.com/en/ethw/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ETHW', multiplier: '1000000000000000000', @@ -104,7 +100,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mΞ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const ethereumpow = makeOuterPlugin({ diff --git a/src/ethereum/info/fantomInfo.ts b/src/ethereum/info/fantomInfo.ts index 50d473499..2ba763041 100644 --- a/src/ethereum/info/fantomInfo.ts +++ b/src/ethereum/info/fantomInfo.ts @@ -308,28 +308,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'FTM', displayName: 'Fantom', pluginId: 'fantom', walletType: 'wallet:fantom', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://ftmscan.com/address/%s', transactionExplorer: 'https://ftmscan.com/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'FTM', multiplier: '1000000000000000000', symbol: 'F' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const fantom = makeOuterPlugin({ diff --git a/src/ethereum/info/goerliInfo.ts b/src/ethereum/info/goerliInfo.ts index 9d9f23588..73dbf3d78 100644 --- a/src/ethereum/info/goerliInfo.ts +++ b/src/ethereum/info/goerliInfo.ts @@ -108,21 +108,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'GOR', displayName: 'Goerli Testnet', pluginId: 'goerli', walletType: 'wallet:goerli', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://etherscan.io/address/%s', transactionExplorer: 'https://etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'GOR', multiplier: '1000000000000000000', @@ -134,7 +130,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mG' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const goerli = makeOuterPlugin({ diff --git a/src/ethereum/info/kovanInfo.ts b/src/ethereum/info/kovanInfo.ts index e41238493..af02670dc 100644 --- a/src/ethereum/info/kovanInfo.ts +++ b/src/ethereum/info/kovanInfo.ts @@ -255,21 +255,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'KOV', displayName: 'Kovan Testnet', pluginId: 'kovan', walletType: 'wallet:kovan', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://etherscan.io/address/%s', transactionExplorer: 'https://etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'KOV', multiplier: '1000000000000000000', @@ -281,7 +277,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mK' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const kovan = makeOuterPlugin({ diff --git a/src/ethereum/info/optimismInfo.ts b/src/ethereum/info/optimismInfo.ts index fd3854230..7af601c4e 100644 --- a/src/ethereum/info/optimismInfo.ts +++ b/src/ethereum/info/optimismInfo.ts @@ -181,28 +181,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ETH', displayName: 'Optimism', pluginId: 'optimism', walletType: 'wallet:optimism', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://optimistic.etherscan.io/address/%s', transactionExplorer: 'https://optimistic.etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ETH', multiplier: '1000000000000000000', symbol: 'Ξ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const optimism = makeOuterPlugin({ diff --git a/src/ethereum/info/polygonInfo.ts b/src/ethereum/info/polygonInfo.ts index 4c73278f6..4a342bf64 100644 --- a/src/ethereum/info/polygonInfo.ts +++ b/src/ethereum/info/polygonInfo.ts @@ -190,21 +190,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'MATIC', displayName: 'Polygon', pluginId: 'polygon', // matching mnemonic here walletType: 'wallet:polygon', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://polygonscan.com/address/%s', transactionExplorer: 'https://polygonscan.com/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'MATIC', multiplier: '1000000000000000000', @@ -216,7 +212,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mMATIC' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const polygon = makeOuterPlugin({ diff --git a/src/ethereum/info/pulsechainInfo.ts b/src/ethereum/info/pulsechainInfo.ts index 4a826fcc1..08fe62fd0 100644 --- a/src/ethereum/info/pulsechainInfo.ts +++ b/src/ethereum/info/pulsechainInfo.ts @@ -75,21 +75,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'PLS', displayName: 'PulseChain', pluginId: 'pulsechain', walletType: 'wallet:pulsechain', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://scan.pulsechain.com/address/%s', transactionExplorer: 'https://scan.pulsechain.com/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'PLS', multiplier: '1000000000000000000', @@ -101,7 +97,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mPLS' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const pulsechain = makeOuterPlugin({ diff --git a/src/ethereum/info/rinkebyInfo.ts b/src/ethereum/info/rinkebyInfo.ts index df07da16b..9d3ea50bc 100644 --- a/src/ethereum/info/rinkebyInfo.ts +++ b/src/ethereum/info/rinkebyInfo.ts @@ -108,21 +108,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'RIN', displayName: 'Rinkeby Testnet', pluginId: 'rinkeby', walletType: 'wallet:rinkeby', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://etherscan.io/address/%s', transactionExplorer: 'https://etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'RIN', multiplier: '1000000000000000000', @@ -134,7 +130,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mΞ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const rinkeby = makeOuterPlugin({ diff --git a/src/ethereum/info/ropstenInfo.ts b/src/ethereum/info/ropstenInfo.ts index 9060097d6..50817d8af 100644 --- a/src/ethereum/info/ropstenInfo.ts +++ b/src/ethereum/info/ropstenInfo.ts @@ -111,21 +111,17 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ROP', displayName: 'Ropsten Testnet', pluginId: 'ropsten', walletType: 'wallet:ropsten', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://etherscan.io/address/%s', transactionExplorer: 'https://etherscan.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ROP', multiplier: '1000000000000000000', @@ -137,7 +133,11 @@ export const currencyInfo: EdgeCurrencyInfo = { symbol: 'mR' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const ropsten = makeOuterPlugin({ diff --git a/src/ethereum/info/rskInfo.ts b/src/ethereum/info/rskInfo.ts index 1e810f830..afc368403 100644 --- a/src/ethereum/info/rskInfo.ts +++ b/src/ethereum/info/rskInfo.ts @@ -69,28 +69,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'RBTC', displayName: 'Rootstock', pluginId: 'rsk', walletType: 'wallet:rsk', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://explorer.rsk.co/address/%s', transactionExplorer: 'https://explorer.rsk.co/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'RBTC', multiplier: '1000000000000000000', symbol: 'RBTC' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const rsk = makeOuterPlugin({ diff --git a/src/ethereum/info/zksyncInfo.ts b/src/ethereum/info/zksyncInfo.ts index c5f1b9d4f..9bd1d9856 100644 --- a/src/ethereum/info/zksyncInfo.ts +++ b/src/ethereum/info/zksyncInfo.ts @@ -74,28 +74,28 @@ const defaultSettings: any = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: + canReplaceByFee: true, currencyCode: 'ETH', displayName: 'zkSync', pluginId: 'zksync', walletType: 'wallet:zksync', - memoType: 'hex', - - canReplaceByFee: true, - defaultSettings, + // Explorers: addressExplorer: 'https://explorer.zksync.io/address/%s', transactionExplorer: 'https://explorer.zksync.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ETH', multiplier: '1000000000000000000', symbol: 'Ξ' } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + + // Deprecated: + defaultSettings, + memoType: 'hex', + metaTokens: makeMetaTokens(builtinTokens) } export const zksync = makeOuterPlugin({ diff --git a/src/filecoin/filecoinInfo.ts b/src/filecoin/filecoinInfo.ts index 0a2d102e6..f182f26ab 100644 --- a/src/filecoin/filecoinInfo.ts +++ b/src/filecoin/filecoinInfo.ts @@ -16,20 +16,18 @@ const networkInfo: FilecoinNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'FIL', displayName: 'Filecoin', pluginId: 'filecoin', requiredConfirmations: 900, + unsafeBroadcastTx: true, walletType: 'wallet:filecoin', - defaultSettings: {}, - + // Explorers: addressExplorer: 'https://filscan.io/en/address/%s', transactionExplorer: 'https://filscan.io/en/message/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'FIL', multiplier: '1000000000000000000', @@ -67,9 +65,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], - metaTokens: [], // Deprecated - - unsafeBroadcastTx: true + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const filecoin = makeOuterPlugin({ diff --git a/src/fio/fioInfo.ts b/src/fio/fioInfo.ts index df1c67699..49444a40b 100644 --- a/src/fio/fioInfo.ts +++ b/src/fio/fioInfo.ts @@ -48,28 +48,27 @@ const networkInfo: FioNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'FIO', displayName: 'FIO', pluginId: 'fio', walletType: 'wallet:fio', + unsafeSyncNetwork: true, - defaultSettings: { ...networkInfo }, - + // Explorers: addressExplorer: 'https://fio.bloks.io/key/%s', transactionExplorer: 'https://fio.bloks.io/transaction/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'FIO', multiplier: '1000000000', symbol: 'ᵮ' } ], - metaTokens: [], // Deprecated - unsafeSyncNetwork: true + // Deprecated: + defaultSettings: { ...networkInfo }, + metaTokens: [] } export const fio = makeOuterPlugin({ diff --git a/src/hedera/hederaInfo.ts b/src/hedera/hederaInfo.ts index 6b3cb6a02..345c6c71b 100644 --- a/src/hedera/hederaInfo.ts +++ b/src/hedera/hederaInfo.ts @@ -14,22 +14,17 @@ const networkInfo: HederaNetworkInfo = { } const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'HBAR', displayName: 'Hedera', pluginId: 'hedera', walletType: 'wallet:hedera', - defaultSettings: {}, - - memoMaxLength: 100, - + // Explorers: addressExplorer: 'https://hashscan.io/mainnet/account/%s', transactionExplorer: 'https://hashscan.io/mainnet/transaction/%s', denominations: [ - // An array of Objects of the possible denominations for this currency - // other denominations are specified but these are the most common + // Other denominations are specified but these are the most common: { name: 'HBAR', multiplier: '100000000', // 100,000,000 @@ -41,7 +36,11 @@ const currencyInfo: EdgeCurrencyInfo = { symbol: 'tℏ' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + memoMaxLength: 100, + metaTokens: [] } export const hedera = makeOuterPlugin({ diff --git a/src/hedera/hederaTestnetInfo.ts b/src/hedera/hederaTestnetInfo.ts index adbf75de7..04588788a 100644 --- a/src/hedera/hederaTestnetInfo.ts +++ b/src/hedera/hederaTestnetInfo.ts @@ -13,20 +13,17 @@ const networkInfo: HederaNetworkInfo = { } const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'THBAR', displayName: 'Hedera Testnet', pluginId: 'hederatestnet', walletType: 'wallet:hederatestnet', - defaultSettings: {}, - + // Explorers: addressExplorer: `https://explorer.kabuto.sh/testnet/id/%s`, transactionExplorer: `https://explorer.kabuto.sh/testnet/transaction/%s`, denominations: [ - // An array of Objects of the possible denominations for this currency - // other denominations are specified but these are the most common + // Other denominations are specified but these are the most common: { name: 'THBAR', multiplier: '100000000', // 100,000,000 @@ -38,7 +35,10 @@ const currencyInfo: EdgeCurrencyInfo = { symbol: 'tℏ' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const hederatestnet = makeOuterPlugin({ diff --git a/src/polkadot/info/liberlandInfo.ts b/src/polkadot/info/liberlandInfo.ts index 7a40af9a6..255874fee 100644 --- a/src/polkadot/info/liberlandInfo.ts +++ b/src/polkadot/info/liberlandInfo.ts @@ -30,6 +30,7 @@ export const currencyInfo: EdgeCurrencyInfo = { pluginId: 'liberland', walletType: 'wallet:liberland', + // Explorers: addressExplorer: '', transactionExplorer: 'https://polkadot.js.org/apps/?rpc=wss%%3A%%2F%%2Fmainnet.liberland.org%%2F#/explorer/query/%s', @@ -42,9 +43,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], - // Deprecated + // Deprecated: defaultSettings: {}, - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + metaTokens: makeMetaTokens(builtinTokens) } export const liberland = makeOuterPlugin({ diff --git a/src/polkadot/info/liberlandTestnetInfo.ts b/src/polkadot/info/liberlandTestnetInfo.ts index 3eccdc595..27c58525a 100644 --- a/src/polkadot/info/liberlandTestnetInfo.ts +++ b/src/polkadot/info/liberlandTestnetInfo.ts @@ -30,6 +30,7 @@ export const currencyInfo: EdgeCurrencyInfo = { pluginId: 'liberlandtestnet', walletType: 'wallet:liberlandtestnet', + // Explorers: addressExplorer: '', transactionExplorer: 'https://polkadot.js.org/apps/?rpc=wss%%3A%%2F%%2Ftestchain.liberland.org%%2F#/explorer/query/%s', @@ -42,9 +43,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], - // Deprecated + // Deprecated: defaultSettings: {}, - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + metaTokens: makeMetaTokens(builtinTokens) } export const liberlandtestnet = makeOuterPlugin< diff --git a/src/polkadot/info/polkadotInfo.ts b/src/polkadot/info/polkadotInfo.ts index b5dbe024e..55ec060ed 100644 --- a/src/polkadot/info/polkadotInfo.ts +++ b/src/polkadot/info/polkadotInfo.ts @@ -13,26 +13,26 @@ const networkInfo: PolkadotNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'DOT', displayName: 'Polkadot', pluginId: 'polkadot', walletType: 'wallet:polkadot', - defaultSettings: {}, - + // Explorers: addressExplorer: 'https://polkadot.subscan.io/account/%s', transactionExplorer: 'https://polkadot.subscan.io/extrinsic/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'DOT', multiplier: '10000000000', symbol: '' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const polkadot = makeOuterPlugin({ diff --git a/src/ripple/rippleInfo.ts b/src/ripple/rippleInfo.ts index 4f24bfa7d..c11d6d329 100644 --- a/src/ripple/rippleInfo.ts +++ b/src/ripple/rippleInfo.ts @@ -15,29 +15,28 @@ const networkInfo: XrpNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'XRP', displayName: 'XRP', pluginId: 'ripple', walletType: 'wallet:ripple', - defaultSettings: {}, - - memoMaxLength: 10, - memoMaxValue: '4294967295', - + // Explorers: addressExplorer: 'https://xrpscan.com/account/%s', transactionExplorer: 'https://xrpscan.com/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'XRP', multiplier: '1000000', symbol: 'X' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + memoMaxLength: 10, + memoMaxValue: '4294967295', + metaTokens: [] } export const builtinTokens: EdgeTokenMap = { diff --git a/src/solana/solanaInfo.ts b/src/solana/solanaInfo.ts index 302c0d0f2..2cd322d9c 100644 --- a/src/solana/solanaInfo.ts +++ b/src/solana/solanaInfo.ts @@ -17,26 +17,26 @@ const networkInfo: SolanaNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'SOL', displayName: 'Solana', pluginId: 'solana', walletType: 'wallet:solana', - defaultSettings: {}, - + // Explorers: addressExplorer: 'https://explorer.solana.com/address/%s', transactionExplorer: 'https://explorer.solana.com/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'SOL', multiplier: '1000000000', symbol: '◎' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const solana = makeOuterPlugin({ diff --git a/src/stellar/stellarInfo.ts b/src/stellar/stellarInfo.ts index c2d5085db..c33d13027 100644 --- a/src/stellar/stellarInfo.ts +++ b/src/stellar/stellarInfo.ts @@ -10,28 +10,27 @@ const networkInfo: StellarNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'XLM', displayName: 'Stellar', pluginId: 'stellar', walletType: 'wallet:stellar', - defaultSettings: {}, - - memoMaxLength: 19, - + // Explorers: addressExplorer: 'https://stellarchain.io/address/%s', transactionExplorer: 'https://stellarchain.io/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'XLM', multiplier: '10000000', symbol: '*' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + memoMaxLength: 19, + metaTokens: [] } export const stellar = makeOuterPlugin({ diff --git a/src/tezos/tezosInfo.ts b/src/tezos/tezosInfo.ts index 21a0ca7fa..3cec55a0e 100644 --- a/src/tezos/tezosInfo.ts +++ b/src/tezos/tezosInfo.ts @@ -36,26 +36,26 @@ const networkInfo: TezosNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'XTZ', displayName: 'Tezos', pluginId: 'tezos', walletType: 'wallet:tezos', - defaultSettings: {}, - + // Explorers: addressExplorer: 'https://tzstats.com/%s', transactionExplorer: 'https://tzstats.com/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'XTZ', multiplier: '1000000', symbol: 't' } ], - metaTokens: [] // Deprecated + + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const tezos = makeOuterPlugin({ diff --git a/src/tron/tronInfo.ts b/src/tron/tronInfo.ts index 652feeff7..db11d309b 100644 --- a/src/tron/tronInfo.ts +++ b/src/tron/tronInfo.ts @@ -110,21 +110,16 @@ export const networkInfo: TronNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'TRX', displayName: 'Tron', pluginId: 'tron', walletType: 'wallet:tron', - defaultSettings: {}, - - memoType: 'text', - + // Explorers: addressExplorer: 'https://tronscan.org/#/address/%s', transactionExplorer: 'https://tronscan.org/#/transaction/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'TRX', multiplier: '1000000', @@ -132,7 +127,10 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], - metaTokens: makeMetaTokens(builtinTokens) // Deprecated + // Deprecated: + defaultSettings: {}, + memoType: 'text', + metaTokens: makeMetaTokens(builtinTokens) } export const tron = makeOuterPlugin({ diff --git a/src/zcash/piratechainInfo.ts b/src/zcash/piratechainInfo.ts index e3c47a88b..ce0f4b797 100644 --- a/src/zcash/piratechainInfo.ts +++ b/src/zcash/piratechainInfo.ts @@ -19,29 +19,28 @@ const networkInfo: ZcashNetworkInfo = { } const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'ARRR', displayName: 'Pirate Chain', pluginId: 'piratechain', requiredConfirmations: 10, + unsafeBroadcastTx: true, walletType: 'wallet:piratechain', - defaultSettings: {}, - + // Explorers: addressExplorer: '', transactionExplorer: 'https://explorer.pirate.black/tx/%s', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ARRR', multiplier: '100000000', symbol: 'P' } ], - metaTokens: [], // Deprecated - unsafeBroadcastTx: true + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const piratechain = makeOuterPlugin({ diff --git a/src/zcash/zcashInfo.ts b/src/zcash/zcashInfo.ts index 15e731e6f..b0d833b71 100644 --- a/src/zcash/zcashInfo.ts +++ b/src/zcash/zcashInfo.ts @@ -17,21 +17,19 @@ const networkInfo: ZcashNetworkInfo = { } export const currencyInfo: EdgeCurrencyInfo = { - // Basic currency information: currencyCode: 'ZEC', displayName: 'Zcash', pluginId: 'zcash', requiredConfirmations: 10, + unsafeBroadcastTx: true, walletType: 'wallet:zcash', - defaultSettings: {}, - + // Explorers: addressExplorer: 'https://blockchair.com/zcash/address/%s?from=edgeapp', transactionExplorer: 'https://blockchair.com/zcash/transaction/%s?from=edgeapp', denominations: [ - // An array of Objects of the possible denominations for this currency { name: 'ZEC', multiplier: '100000000', @@ -39,9 +37,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], - metaTokens: [], // Deprecated - - unsafeBroadcastTx: true + // Deprecated: + defaultSettings: {}, + metaTokens: [] } export const zcash = makeOuterPlugin({ From b2996eebcc58c5315d372f63f1d73c80699674da Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 24 Aug 2023 13:46:39 -0700 Subject: [PATCH 5/8] Copy the utf8 utility from edge-core-js --- src/common/utf8.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/common/utf8.ts diff --git a/src/common/utf8.ts b/src/common/utf8.ts new file mode 100644 index 000000000..a47ffeece --- /dev/null +++ b/src/common/utf8.ts @@ -0,0 +1,32 @@ +export const utf8 = { + parse(text: string): Uint8Array { + const byteString = encodeURI(text) + const out = new Uint8Array(byteString.length) + + // Treat each character as a byte, except for %XX escape sequences: + let di = 0 // Destination index + for (let i = 0; i < byteString.length; ++i) { + const c = byteString.charCodeAt(i) + if (c === 0x25) { + out[di++] = parseInt(byteString.slice(i + 1, i + 3), 16) + i += 2 + } else { + out[di++] = c + } + } + + // Trim any over-allocated space (zero-copy): + return out.subarray(0, di) + }, + + stringify(data: Uint8Array | number[]): string { + // Create a %XX escape sequence for each input byte: + let byteString = '' + for (let i = 0; i < data.length; ++i) { + const byte = data[i] + byteString += '%' + (byte >> 4).toString(16) + (byte & 0xf).toString(16) + } + + return decodeURIComponent(byteString) + } +} From a7d8561c3f0afdb5930a25ef6ff72cb0e0b38fd4 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 17 Aug 2023 10:45:21 -0700 Subject: [PATCH 6/8] Add modern memo handling to all plugins --- src/algorand/AlgorandEngine.ts | 20 ++-- src/algorand/algorandInfo.ts | 3 + src/algorand/algorandTestnetInfo.ts | 3 + src/binance/BinanceEngine.ts | 10 +- src/binance/binanceInfo.ts | 4 + src/common/types.ts | 10 ++ src/common/upgradeMemos.ts | 47 +++++++++ src/common/validateMemos.ts | 107 +++++++++++++++++++++ src/eos/EosEngine.ts | 15 ++- src/eos/info/eosCommonInfo.ts | 10 ++ src/eos/info/eosInfo.ts | 2 + src/eos/info/telosInfo.ts | 2 + src/eos/info/waxInfo.ts | 2 + src/ethereum/EthereumEngine.ts | 14 +-- src/ethereum/info/avalancheInfo.ts | 2 + src/ethereum/info/binancesmartchainInfo.ts | 2 + src/ethereum/info/celoInfo.ts | 2 + src/ethereum/info/ethDevInfo.ts | 2 + src/ethereum/info/ethereumCommonInfo.ts | 10 ++ src/ethereum/info/ethereumInfo.ts | 2 + src/ethereum/info/ethereumclassicInfo.ts | 2 + src/ethereum/info/ethereumpowInfo.ts | 2 + src/ethereum/info/fantomInfo.ts | 2 + src/ethereum/info/goerliInfo.ts | 2 + src/ethereum/info/kovanInfo.ts | 2 + src/ethereum/info/optimismInfo.ts | 2 + src/ethereum/info/polygonInfo.ts | 2 + src/ethereum/info/pulsechainInfo.ts | 2 + src/ethereum/info/rinkebyInfo.ts | 2 + src/ethereum/info/ropstenInfo.ts | 2 + src/ethereum/info/rskInfo.ts | 2 + src/ethereum/info/zksyncInfo.ts | 2 + src/filecoin/FilecoinEngine.ts | 5 +- src/fio/FioEngine.ts | 7 +- src/fio/fioInfo.ts | 5 +- src/hedera/HederaEngine.ts | 16 +-- src/hedera/hederaInfo.ts | 4 + src/polkadot/PolkadotEngine.ts | 6 +- src/polkadot/info/polkadotInfo.ts | 3 + src/ripple/RippleEngine.ts | 67 ++++--------- src/ripple/rippleInfo.ts | 9 ++ src/solana/SolanaEngine.ts | 11 ++- src/solana/solanaInfo.ts | 4 + src/stellar/StellarEngine.ts | 25 +++-- src/stellar/stellarInfo.ts | 10 ++ src/tezos/TezosEngine.ts | 6 +- src/tezos/tezosInfo.ts | 3 + src/tron/TronEngine.ts | 16 ++- src/tron/tronInfo.ts | 3 + src/zcash/ZcashEngine.ts | 9 +- src/zcash/piratechainInfo.ts | 3 + src/zcash/zcashInfo.ts | 3 + 52 files changed, 398 insertions(+), 110 deletions(-) create mode 100644 src/common/upgradeMemos.ts create mode 100644 src/common/validateMemos.ts create mode 100644 src/eos/info/eosCommonInfo.ts create mode 100644 src/ethereum/info/ethereumCommonInfo.ts diff --git a/src/algorand/AlgorandEngine.ts b/src/algorand/AlgorandEngine.ts index 75ab696a2..764d0b511 100644 --- a/src/algorand/AlgorandEngine.ts +++ b/src/algorand/AlgorandEngine.ts @@ -26,6 +26,8 @@ import { base16, base64 } from 'rfc4648' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' +import { utf8 } from '../common/utf8' import { asyncWaterfall, cleanTxLogs, @@ -461,6 +463,7 @@ export class AlgorandEngine extends CurrencyEngine< } async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise { + spendInfo = upgradeMemos(spendInfo, this.currencyInfo) let balance = this.getBalance({ currencyCode: spendInfo.currencyCode }) @@ -509,8 +512,10 @@ export class AlgorandEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode, nativeBalance } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo const spendableAlgoBalance = sub( this.getBalance({ @@ -523,11 +528,8 @@ export class AlgorandEngine extends CurrencyEngine< throw new Error('Error: only one output allowed') } - const { - nativeAmount: amount, - memo, - publicAddress - } = edgeSpendInfo.spendTargets[0] + const { nativeAmount: amount, publicAddress } = + edgeSpendInfo.spendTargets[0] if (publicAddress == null) throw new Error('makeSpend Missing publicAddress') @@ -539,10 +541,8 @@ export class AlgorandEngine extends CurrencyEngine< type: currencyCode === this.currencyInfo.currencyCode ? 'pay' : 'axfer' } - let note: Uint8Array | undefined - if (memo != null) { - note = Uint8Array.from(Buffer.from(memo, 'ascii')) - } + const note = + memos[0]?.type === 'text' ? utf8.parse(memos[0].value) : undefined const { customNetworkFee } = edgeSpendInfo const customFee = asMaybeCustomFee(customNetworkFee).fee @@ -628,7 +628,7 @@ export class AlgorandEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, - memos: [], + memos, nativeAmount, networkFee, otherParams, diff --git a/src/algorand/algorandInfo.ts b/src/algorand/algorandInfo.ts index f61d68e4f..26fb094da 100644 --- a/src/algorand/algorandInfo.ts +++ b/src/algorand/algorandInfo.ts @@ -50,6 +50,9 @@ const currencyInfo: EdgeCurrencyInfo = { } ], + // https://developer.algorand.org/docs/get-details/transactions/transactions/ + memoOptions: [{ type: 'text', memoName: 'note', maxLength: 1000 }], + // Deprecated: defaultSettings: { customFeeSettings: ['fee'] }, memoType: 'text', diff --git a/src/algorand/algorandTestnetInfo.ts b/src/algorand/algorandTestnetInfo.ts index 8e699680a..ce29100fd 100644 --- a/src/algorand/algorandTestnetInfo.ts +++ b/src/algorand/algorandTestnetInfo.ts @@ -43,6 +43,9 @@ const currencyInfo: EdgeCurrencyInfo = { } ], + // https://developer.algorand.org/docs/get-details/transactions/transactions/ + memoOptions: [{ type: 'text', memoName: 'note', maxLength: 1000 }], + // Deprecated: defaultSettings: { customFeeSettings: ['fee'] }, memoType: 'text', diff --git a/src/binance/BinanceEngine.ts b/src/binance/BinanceEngine.ts index 979bb46dd..cb591cce7 100644 --- a/src/binance/BinanceEngine.ts +++ b/src/binance/BinanceEngine.ts @@ -15,6 +15,7 @@ import { import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' import { asErrorMessage } from '../common/types' +import { upgradeMemos } from '../common/upgradeMemos' import { asyncWaterfall, cleanTxLogs, @@ -383,7 +384,9 @@ export class BinanceEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo const spendTarget = edgeSpendInfo.spendTargets[0] const { publicAddress } = spendTarget @@ -408,10 +411,7 @@ export class BinanceEngine extends CurrencyEngine< throw new Error('Binance Beacon Chain token transfers not supported') } - if (edgeSpendInfo.spendTargets[0].otherParams?.uniqueIdentifier != null) { - otherParams.memo = - edgeSpendInfo.spendTargets[0].otherParams.uniqueIdentifier - } + otherParams.memo = memos[0]?.type === 'text' ? memos[0].value : undefined const nativeNetworkFee = NETWORK_FEE_NATIVE_AMOUNT const ErrorInsufficientFundsMoreBnb = new Error( @@ -437,7 +437,7 @@ export class BinanceEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, // date isSend: nativeAmount.startsWith('-'), - memos: [], + memos, nativeAmount, // nativeAmount networkFee: nativeNetworkFee, // networkFee, supposedly fixed otherParams, // otherParams diff --git a/src/binance/binanceInfo.ts b/src/binance/binanceInfo.ts index be15349f4..437ae47ab 100644 --- a/src/binance/binanceInfo.ts +++ b/src/binance/binanceInfo.ts @@ -33,9 +33,13 @@ const currencyInfo: EdgeCurrencyInfo = { } ], + // https://github.com/bnb-chain/javascript-sdk/blob/master/docs/api-docs/classes/bncclient.md#transfer + memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 128 }], + // Deprecated: defaultSettings: {}, memoMaxLength: 128, + memoType: 'text', metaTokens: [] } diff --git a/src/common/types.ts b/src/common/types.ts index dbc193ce8..068f3ffac 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -1,5 +1,6 @@ import { asArray, + asCodec, asEither, asMaybe, asNumber, @@ -11,6 +12,7 @@ import { Cleaner } from 'cleaners' import { EdgeToken, EdgeTokenInfo, EdgeTransaction } from 'edge-core-js/types' +import { base16 } from 'rfc4648' export const DATA_STORE_FILE = 'txEngineFolder/walletLocalData.json' export const TXID_MAP_FILE = 'txEngineFolder/txidMap.json' @@ -75,6 +77,14 @@ export const asSafeCommonWalletInfo = asWalletInfo( asObject({ publicKey: asString }) ) +/** + * A string of hex-encoded binary data. + */ +export const asBase16: Cleaner = asCodec( + raw => base16.parse(asString(raw)), + clean => base16.stringify(clean).toLowerCase() +) + export function asIntegerString(raw: unknown): string { const clean = asString(raw) if (!/^\d+$/.test(clean)) { diff --git a/src/common/upgradeMemos.ts b/src/common/upgradeMemos.ts new file mode 100644 index 000000000..e464da271 --- /dev/null +++ b/src/common/upgradeMemos.ts @@ -0,0 +1,47 @@ +import { EdgeCurrencyInfo, EdgeMemo, EdgeSpendInfo } from 'edge-core-js/types' + +import { validateMemos } from './validateMemos' + +/** + * Upgrades the memo fields inside an EdgeSpendTarget, + * since we need to be runtime-compatible with legacy core versions. + */ +export function upgradeMemos( + spendInfo: EdgeSpendInfo, + currencyInfo: EdgeCurrencyInfo +): EdgeSpendInfo { + const { memoType } = currencyInfo + + const legacyMemos: EdgeMemo[] = [] + + // If this chain supports legacy memos, grab those: + if (memoType === 'hex' || memoType === 'number' || memoType === 'text') { + for (const target of spendInfo.spendTargets) { + if (target.memo != null) { + legacyMemos.push({ + type: memoType, + value: target.memo + }) + } else if (target.uniqueIdentifier != null) { + legacyMemos.push({ + type: memoType, + value: target.uniqueIdentifier + }) + } else if (typeof target.otherParams?.uniqueIdentifier === 'string') { + legacyMemos.push({ + type: memoType, + value: target.otherParams.uniqueIdentifier + }) + } + } + } + + // If we don't have modern memos, use the legacy ones: + const out: EdgeSpendInfo = { + ...spendInfo, + memos: spendInfo.memos ?? legacyMemos + } + + validateMemos(out, currencyInfo) + return out +} diff --git a/src/common/validateMemos.ts b/src/common/validateMemos.ts new file mode 100644 index 000000000..bb08f5c7c --- /dev/null +++ b/src/common/validateMemos.ts @@ -0,0 +1,107 @@ +import { gt } from 'biggystring' +import { asMaybe } from 'cleaners' +import { + EdgeCurrencyInfo, + EdgeMemo, + EdgeMemoOption, + EdgeSpendInfo +} from 'edge-core-js/types' + +import { asBase16, asIntegerString } from './types' + +/** + * Validates the memos on an spend request. + * Throws an error if any of the memos are wrong. + */ +export function validateMemos( + spendInfo: EdgeSpendInfo, + currencyInfo: EdgeCurrencyInfo +): void { + const { memos = [] } = spendInfo + const { + displayName, + memoMaxLength, + memoMaxValue, + memoOptions = [], + multipleMemos = false, + memoType + } = currencyInfo + + // Not all coins keep the legacy memo type in the modern list, + // but we still need to validate the legacy type if present: + const allOptions = [...memoOptions] + if (memoType === 'text') { + allOptions.push({ type: 'text', maxLength: memoMaxLength }) + } + if (memoType === 'number') { + allOptions.push({ type: 'number', maxValue: memoMaxValue }) + } + if (memoType === 'hex') { + allOptions.push({ + type: 'hex', + maxBytes: memoMaxLength == null ? undefined : memoMaxLength / 2 + }) + } + + // What we should call a "memo" in our error messages: + const { memoName = 'memo' } = memoOptions[0] ?? {} + + // Now validate our memos: + for (const memo of memos) { + const options = allOptions.filter(option => memo.type === option.type) + if (options.length < 1) { + throw new Error(`${displayName} ${memoName}: cannot be type ${memo.type}`) + } + const problem = options + .map(option => getMemoError(memo, option)) + .find(problem => problem != null) + if (problem != null) { + throw new Error(`${displayName} {memoName}: ${problem}`) + } + } + + // Validate the number of memos: + if (!multipleMemos && memos.length > 1) { + throw new Error(`${displayName} only supports one ${memoName}`) + } +} + +/** + * Checks a memo against a memo option. + * Returns `undefined` if valid, or an error string if invalid. + */ +function getMemoError( + memo: EdgeMemo, + option: EdgeMemoOption +): string | undefined { + if ( + option.type === 'text' && + option.maxLength != null && + memo.value.length > option.maxLength + ) { + return `cannot be longer than ${option.maxLength}` + } + + if (option.type === 'number') { + const value = asMaybe(asIntegerString)(memo.value) + if (value == null) { + return `is not a valid number` + } + if (option.maxValue != null && gt(value, option.maxValue)) { + return `cannot be greater than ${option.maxValue}` + } + } + + if (option.type === 'hex') { + const value = asMaybe(asBase16)(memo.value) + if (value == null) { + return `is not valid hexadecimal` + } + if (option.maxBytes != null && value.length > option.maxBytes) { + return `cannot be longer than ${option.maxBytes} bytes` + } + if (option.minBytes != null && value.length < option.minBytes) { + return `cannot be shorter than ${option.minBytes} bytes` + } + } +} diff --git a/src/eos/EosEngine.ts b/src/eos/EosEngine.ts index a0d67c4dd..de1ad93fb 100644 --- a/src/eos/EosEngine.ts +++ b/src/eos/EosEngine.ts @@ -27,6 +27,7 @@ import parse from 'url-parse' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { asyncWaterfall, cleanTxLogs, @@ -952,8 +953,11 @@ export class EosEngine extends CurrencyEngine { } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode, nativeBalance, denom } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo + const tokenInfo = this.getTokenInfo(currencyCode) if (tokenInfo == null) throw new Error('Unable to find token info') const { contractAddress = 'eosio.token' } = tokenInfo @@ -1013,14 +1017,7 @@ export class EosEngine extends CurrencyEngine { const quantity = toFixed(exchangeAmount, nativePrecision) + ` ${currencyCode}` - let memo = '' - if ( - edgeSpendInfo.spendTargets[0].otherParams != null && - typeof edgeSpendInfo.spendTargets[0].otherParams.uniqueIdentifier === - 'string' - ) { - memo = edgeSpendInfo.spendTargets[0].otherParams.uniqueIdentifier - } + const memo = memos[0]?.type === 'text' ? memos[0].value : undefined const transferActions: EosTransfer[] = [ { @@ -1048,7 +1045,7 @@ export class EosEngine extends CurrencyEngine { currencyCode, // currencyCode date: 0, // date isSend: nativeAmount.startsWith('-'), - memos: [], + memos, nativeAmount, // nativeAmount networkFee, // networkFee otherParams: { diff --git a/src/eos/info/eosCommonInfo.ts b/src/eos/info/eosCommonInfo.ts new file mode 100644 index 000000000..b27fe5e68 --- /dev/null +++ b/src/eos/info/eosCommonInfo.ts @@ -0,0 +1,10 @@ +import { EdgeMemoOption } from 'edge-core-js/types' + +// https://developers.eos.io/manuals/eos/v2.1/cleos/command-reference/transfer +export const eosMemoOptions: EdgeMemoOption[] = [ + { + type: 'text', + memoName: 'memo', + maxLength: 256 + } +] diff --git a/src/eos/info/eosInfo.ts b/src/eos/info/eosInfo.ts index 47c4fff8d..fc618989a 100644 --- a/src/eos/info/eosInfo.ts +++ b/src/eos/info/eosInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import type { EosTools } from '../EosTools' import type { EosNetworkInfo } from '../eosTypes' import { eosOtherMethodNames } from '../eosTypes' +import { eosMemoOptions } from './eosCommonInfo' // ----EOSIO MAIN NET---- export const eosNetworkInfo: EosNetworkInfo = { @@ -30,6 +31,7 @@ export const eosNetworkInfo: EosNetworkInfo = { export const eosCurrencyInfo: EdgeCurrencyInfo = { currencyCode: 'EOS', displayName: 'EOS', + memoOptions: eosMemoOptions, pluginId: 'eos', unsafeBroadcastTx: true, walletType: 'wallet:eos', diff --git a/src/eos/info/telosInfo.ts b/src/eos/info/telosInfo.ts index 94a92561e..6cf91783d 100644 --- a/src/eos/info/telosInfo.ts +++ b/src/eos/info/telosInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import type { EosTools } from '../EosTools' import type { EosNetworkInfo } from '../eosTypes' import { eosOtherMethodNames } from '../eosTypes' +import { eosMemoOptions } from './eosCommonInfo' // ----TELOS MAIN NET---- export const telosNetworkInfo: EosNetworkInfo = { @@ -23,6 +24,7 @@ export const telosNetworkInfo: EosNetworkInfo = { export const telosCurrencyInfo: EdgeCurrencyInfo = { currencyCode: 'TLOS', displayName: 'Telos', + memoOptions: eosMemoOptions, pluginId: 'telos', walletType: 'wallet:telos', diff --git a/src/eos/info/waxInfo.ts b/src/eos/info/waxInfo.ts index ec3747161..1c60b638a 100644 --- a/src/eos/info/waxInfo.ts +++ b/src/eos/info/waxInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import type { EosTools } from '../EosTools' import type { EosNetworkInfo } from '../eosTypes' import { eosOtherMethodNames } from '../eosTypes' +import { eosMemoOptions } from './eosCommonInfo' // ----WAX MAIN NET---- export const waxNetworkInfo: EosNetworkInfo = { @@ -19,6 +20,7 @@ export const waxNetworkInfo: EosNetworkInfo = { export const waxCurrencyInfo: EdgeCurrencyInfo = { currencyCode: 'WAX', displayName: 'Wax', + memoOptions: eosMemoOptions, pluginId: 'wax', walletType: 'wallet:wax', diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index 4768491fc..02c702835 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -25,6 +25,7 @@ import ethWallet from 'ethereumjs-wallet' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { biggyRoundToNearestInt, bufToHex, @@ -716,6 +717,7 @@ export class EthereumEngine extends CurrencyEngine< } async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise { + spendInfo = upgradeMemos(spendInfo, this.currencyInfo) const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(spendInfo) const balance = this.getBalance({ @@ -809,17 +811,13 @@ export class EthereumEngine extends CurrencyEngine< currencyCode: string, currencyInfo: EdgeCurrencyInfo ): EthereumTxParameterInformation { + const { memos = [] } = edgeSpendInfo const { spendTargets } = edgeSpendInfo const spendTarget = spendTargets[0] const { publicAddress, nativeAmount } = spendTarget // Get data: - let data: string | undefined = - spendTarget.memo ?? spendTarget.otherParams?.data - if (data != null && data.length > 0 && !isHex(data)) { - throw new Error(`Memo/data field must be of type 'hex'`) - } - if (data === '') data = undefined + let data = memos[0]?.type === 'hex' ? memos[0].value : undefined // Get contractAddress and/or value: let value: string | undefined @@ -865,8 +863,10 @@ export class EthereumEngine extends CurrencyEngine< // eslint-disable-next-line @typescript-eslint/explicit-function-return-type async makeSpend(edgeSpendInfoIn: EdgeSpendInfo) { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode, skipChecks } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo const { pendingTxs = [] } = edgeSpendInfo @@ -1025,7 +1025,7 @@ export class EthereumEngine extends CurrencyEngine< date: 0, // date feeRateUsed: getFeeRateUsed(miningFees.gasPrice, otherParams.gas), isSend: nativeAmount.startsWith('-'), - memos: [], + memos, nativeAmount, // nativeAmount networkFee: nativeNetworkFee, // networkFee otherParams, // otherParams diff --git a/src/ethereum/info/avalancheInfo.ts b/src/ethereum/info/avalancheInfo.ts index c0a5581be..447164f49 100644 --- a/src/ethereum/info/avalancheInfo.ts +++ b/src/ethereum/info/avalancheInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '60781c2586d68229fde47564546784ab3faca982': { @@ -210,6 +211,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'AVAX', displayName: 'Avalanche', + memoOptions: evmMemoOptions, pluginId: 'avalanche', // matching mnemonic here walletType: 'wallet:avalanche', diff --git a/src/ethereum/info/binancesmartchainInfo.ts b/src/ethereum/info/binancesmartchainInfo.ts index f3677e1f7..f58c846d9 100644 --- a/src/ethereum/info/binancesmartchainInfo.ts +++ b/src/ethereum/info/binancesmartchainInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { e9e7cea3dedca5984780bafc599bd69add087d56: { @@ -85,6 +86,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'BNB', displayName: 'BNB Smart Chain', + memoOptions: evmMemoOptions, pluginId: 'binancesmartchain', walletType: 'wallet:binancesmartchain', diff --git a/src/ethereum/info/celoInfo.ts b/src/ethereum/info/celoInfo.ts index 971f570b0..42696d3a1 100644 --- a/src/ethereum/info/celoInfo.ts +++ b/src/ethereum/info/celoInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '765de816845861e75a25fca122bb6898b8b1282a': { @@ -90,6 +91,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'CELO', displayName: 'Celo', + memoOptions: evmMemoOptions, pluginId: 'celo', walletType: 'wallet:celo', diff --git a/src/ethereum/info/ethDevInfo.ts b/src/ethereum/info/ethDevInfo.ts index 00214c07a..b93d2b110 100644 --- a/src/ethereum/info/ethDevInfo.ts +++ b/src/ethereum/info/ethDevInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { ff795577d9ac8bd7d90ee22b6c1703490b6512fd: { @@ -133,6 +134,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ETH', displayName: 'Dev Ethereum', + memoOptions: evmMemoOptions, pluginId: 'ethDev', walletType: 'wallet:ethDev', diff --git a/src/ethereum/info/ethereumCommonInfo.ts b/src/ethereum/info/ethereumCommonInfo.ts new file mode 100644 index 000000000..97a706670 --- /dev/null +++ b/src/ethereum/info/ethereumCommonInfo.ts @@ -0,0 +1,10 @@ +import { EdgeMemoOption } from 'edge-core-js/types' + +// We are using the memo to pass Ethereum contract calls: +export const evmMemoOptions: EdgeMemoOption[] = [ + { + type: 'hex', + hidden: true, + memoName: 'data' + } +] diff --git a/src/ethereum/info/ethereumInfo.ts b/src/ethereum/info/ethereumInfo.ts index 32f4b88c7..c49188fed 100644 --- a/src/ethereum/info/ethereumInfo.ts +++ b/src/ethereum/info/ethereumInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '111111111117dc0aa78b770fa6a738034120c302': { @@ -1115,6 +1116,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ETH', displayName: 'Ethereum', + memoOptions: evmMemoOptions, pluginId: 'ethereum', walletType: 'wallet:ethereum', diff --git a/src/ethereum/info/ethereumclassicInfo.ts b/src/ethereum/info/ethereumclassicInfo.ts index 74af5450a..6e2a23865 100644 --- a/src/ethereum/info/ethereumclassicInfo.ts +++ b/src/ethereum/info/ethereumclassicInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '2c78f1b70ccf63cdee49f9233e9faa99d43aa07e': { @@ -100,6 +101,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ETC', displayName: 'Ethereum Classic', + memoOptions: evmMemoOptions, pluginId: 'ethereumclassic', walletType: 'wallet:ethereumclassic', diff --git a/src/ethereum/info/ethereumpowInfo.ts b/src/ethereum/info/ethereumpowInfo.ts index 5a67b71ff..eb04fa432 100644 --- a/src/ethereum/info/ethereumpowInfo.ts +++ b/src/ethereum/info/ethereumpowInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '2ad7868ca212135c6119fd7ad1ce51cfc5702892': { @@ -81,6 +82,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ETHW', displayName: 'EthereumPoW', + memoOptions: evmMemoOptions, pluginId: 'ethereumpow', walletType: 'wallet:ethereumpow', diff --git a/src/ethereum/info/fantomInfo.ts b/src/ethereum/info/fantomInfo.ts index 2ba763041..5def1ebfa 100644 --- a/src/ethereum/info/fantomInfo.ts +++ b/src/ethereum/info/fantomInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '511d35c52a3c244e7b8bd92c0c297755fbd89212': { @@ -311,6 +312,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'FTM', displayName: 'Fantom', + memoOptions: evmMemoOptions, pluginId: 'fantom', walletType: 'wallet:fantom', diff --git a/src/ethereum/info/goerliInfo.ts b/src/ethereum/info/goerliInfo.ts index 73dbf3d78..30dec1913 100644 --- a/src/ethereum/info/goerliInfo.ts +++ b/src/ethereum/info/goerliInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = {} @@ -111,6 +112,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'GOR', displayName: 'Goerli Testnet', + memoOptions: evmMemoOptions, pluginId: 'goerli', walletType: 'wallet:goerli', diff --git a/src/ethereum/info/kovanInfo.ts b/src/ethereum/info/kovanInfo.ts index af02670dc..f7616709f 100644 --- a/src/ethereum/info/kovanInfo.ts +++ b/src/ethereum/info/kovanInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { b597cd8d3217ea6477232f9217fa70837ff667af: { @@ -258,6 +259,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'KOV', displayName: 'Kovan Testnet', + memoOptions: evmMemoOptions, pluginId: 'kovan', walletType: 'wallet:kovan', diff --git a/src/ethereum/info/optimismInfo.ts b/src/ethereum/info/optimismInfo.ts index 7af601c4e..d271eb9d6 100644 --- a/src/ethereum/info/optimismInfo.ts +++ b/src/ethereum/info/optimismInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '4200000000000000000000000000000000000006': { @@ -184,6 +185,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ETH', displayName: 'Optimism', + memoOptions: evmMemoOptions, pluginId: 'optimism', walletType: 'wallet:optimism', diff --git a/src/ethereum/info/polygonInfo.ts b/src/ethereum/info/polygonInfo.ts index 4a342bf64..392ceac02 100644 --- a/src/ethereum/info/polygonInfo.ts +++ b/src/ethereum/info/polygonInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '2791bca1f2de4661ed88a30c99a7a9449aa84174': { @@ -193,6 +194,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'MATIC', displayName: 'Polygon', + memoOptions: evmMemoOptions, pluginId: 'polygon', // matching mnemonic here walletType: 'wallet:polygon', diff --git a/src/ethereum/info/pulsechainInfo.ts b/src/ethereum/info/pulsechainInfo.ts index 08fe62fd0..9ed9380c2 100644 --- a/src/ethereum/info/pulsechainInfo.ts +++ b/src/ethereum/info/pulsechainInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { a1077a294dde1b09bb078844df40758a5d0f9a27: { @@ -78,6 +79,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'PLS', displayName: 'PulseChain', + memoOptions: evmMemoOptions, pluginId: 'pulsechain', walletType: 'wallet:pulsechain', diff --git a/src/ethereum/info/rinkebyInfo.ts b/src/ethereum/info/rinkebyInfo.ts index 9d3ea50bc..501084c59 100644 --- a/src/ethereum/info/rinkebyInfo.ts +++ b/src/ethereum/info/rinkebyInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = {} @@ -111,6 +112,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'RIN', displayName: 'Rinkeby Testnet', + memoOptions: evmMemoOptions, pluginId: 'rinkeby', walletType: 'wallet:rinkeby', diff --git a/src/ethereum/info/ropstenInfo.ts b/src/ethereum/info/ropstenInfo.ts index 50817d8af..0a3701469 100644 --- a/src/ethereum/info/ropstenInfo.ts +++ b/src/ethereum/info/ropstenInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = {} @@ -114,6 +115,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ROP', displayName: 'Ropsten Testnet', + memoOptions: evmMemoOptions, pluginId: 'ropsten', walletType: 'wallet:ropsten', diff --git a/src/ethereum/info/rskInfo.ts b/src/ethereum/info/rskInfo.ts index afc368403..93808a687 100644 --- a/src/ethereum/info/rskInfo.ts +++ b/src/ethereum/info/rskInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '2acc95758f8b5f583470ba265eb685a8f45fc9d5': { @@ -72,6 +73,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'RBTC', displayName: 'Rootstock', + memoOptions: evmMemoOptions, pluginId: 'rsk', walletType: 'wallet:rsk', diff --git a/src/ethereum/info/zksyncInfo.ts b/src/ethereum/info/zksyncInfo.ts index 9bd1d9856..1eee6aabc 100644 --- a/src/ethereum/info/zksyncInfo.ts +++ b/src/ethereum/info/zksyncInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { EthereumTools } from '../EthereumTools' import type { EthereumFees, EthereumNetworkInfo } from '../ethereumTypes' +import { evmMemoOptions } from './ethereumCommonInfo' const builtinTokens: EdgeTokenMap = { '3355df6d4c9c3035724fd0e3914de96a5a83aaf4': { @@ -77,6 +78,7 @@ export const currencyInfo: EdgeCurrencyInfo = { canReplaceByFee: true, currencyCode: 'ETH', displayName: 'zkSync', + memoOptions: evmMemoOptions, pluginId: 'zksync', walletType: 'wallet:zksync', diff --git a/src/filecoin/FilecoinEngine.ts b/src/filecoin/FilecoinEngine.ts index 971bd1fec..013a92d68 100644 --- a/src/filecoin/FilecoinEngine.ts +++ b/src/filecoin/FilecoinEngine.ts @@ -23,6 +23,7 @@ import { import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { FilecoinTools } from './FilecoinTools' import { asFilecoinPrivateKeys, @@ -161,7 +162,9 @@ export class FilecoinEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo const spendTarget = edgeSpendInfo.spendTargets[0] const { publicAddress, nativeAmount } = spendTarget @@ -196,7 +199,7 @@ export class FilecoinEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, - memos: [], + memos, nativeAmount: txNativeAmount, networkFee, otherParams, diff --git a/src/fio/FioEngine.ts b/src/fio/FioEngine.ts index 946e6fa66..017bd1a65 100644 --- a/src/fio/FioEngine.ts +++ b/src/fio/FioEngine.ts @@ -26,6 +26,7 @@ import { import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { asyncWaterfall, cleanTxLogs, @@ -1378,6 +1379,7 @@ export class FioEngine extends CurrencyEngine { } async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise { + spendInfo = upgradeMemos(spendInfo, this.currencyInfo) const balance = this.getBalance({ currencyCode: spendInfo.currencyCode }) @@ -1399,8 +1401,11 @@ export class FioEngine extends CurrencyEngine { } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, nativeBalance, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo + const lockedBalance = this.walletLocalData.totalBalances[ this.networkInfo.balanceCurrencyCodes.locked @@ -1684,7 +1689,7 @@ export class FioEngine extends CurrencyEngine { currencyCode, date: 0, isSend: true, - memos: [], + memos, nativeAmount: sub(`-${quantity}`, `${fee}`), networkFee: `${fee}`, otherParams: { diff --git a/src/fio/fioInfo.ts b/src/fio/fioInfo.ts index 49444a40b..29a9257ba 100644 --- a/src/fio/fioInfo.ts +++ b/src/fio/fioInfo.ts @@ -51,8 +51,8 @@ export const currencyInfo: EdgeCurrencyInfo = { currencyCode: 'FIO', displayName: 'FIO', pluginId: 'fio', - walletType: 'wallet:fio', unsafeSyncNetwork: true, + walletType: 'wallet:fio', // Explorers: addressExplorer: 'https://fio.bloks.io/key/%s', @@ -66,6 +66,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // No memo support: + memoOptions: [], + // Deprecated: defaultSettings: { ...networkInfo }, metaTokens: [] diff --git a/src/hedera/HederaEngine.ts b/src/hedera/HederaEngine.ts index 96f4bacc1..4bd714a81 100644 --- a/src/hedera/HederaEngine.ts +++ b/src/hedera/HederaEngine.ts @@ -16,6 +16,7 @@ import { base16, base64 } from 'rfc4648' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { getFetchCors, hexToBuf } from '../common/utils' import { HederaTools } from './HederaTools' import { @@ -412,18 +413,19 @@ export class HederaEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) + const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo + if (this.otherData.hederaAccount == null) { throw Error('ErrorAccountNotActivated') } - - const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) - if (edgeSpendInfo.spendTargets.length !== 1) { throw new Error('Error: only one output allowed') } - const { publicAddress, uniqueIdentifier = '' } = - edgeSpendInfo.spendTargets[0] + const memo = memos[0]?.type === 'text' ? memos[0].value : '' + const { publicAddress } = edgeSpendInfo.spendTargets[0] let { nativeAmount } = edgeSpendInfo.spendTargets[0] if (publicAddress == null) @@ -456,7 +458,7 @@ export class HederaEngine extends CurrencyEngine< .addHbarTransfer(this.otherData.hederaAccount, hbar.negated()) .addHbarTransfer(publicAddress, hbar) .setMaxTransactionFee(txnFee) - .setTransactionMemo(uniqueIdentifier) + .setTransactionMemo(memo) .build(this.client) const edgeTransaction: EdgeTransaction = { @@ -464,7 +466,7 @@ export class HederaEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, isSend: true, - memos: [], + memos, nativeAmount: `-${nativeAmount}`, // UI shows the fee subtracted from the sent amount which doesn't make sense here networkFee, // networkFee diff --git a/src/hedera/hederaInfo.ts b/src/hedera/hederaInfo.ts index 345c6c71b..e7b2ee4b2 100644 --- a/src/hedera/hederaInfo.ts +++ b/src/hedera/hederaInfo.ts @@ -37,9 +37,13 @@ const currencyInfo: EdgeCurrencyInfo = { } ], + // https://docs.hedera.com/hedera/sdks-and-apis/sdks/transactions/modify-transaction-fields + memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 100 }], + // Deprecated: defaultSettings: {}, memoMaxLength: 100, + memoType: 'text', metaTokens: [] } diff --git a/src/polkadot/PolkadotEngine.ts b/src/polkadot/PolkadotEngine.ts index d07751ffc..afb904351 100644 --- a/src/polkadot/PolkadotEngine.ts +++ b/src/polkadot/PolkadotEngine.ts @@ -20,6 +20,7 @@ import { base16 } from 'rfc4648' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' import { asMaybeContractLocation } from '../common/tokenHelpers' +import { upgradeMemos } from '../common/upgradeMemos' import { cleanTxLogs, decimalToHex, @@ -321,6 +322,7 @@ export class PolkadotEngine extends CurrencyEngine< } async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise { + spendInfo = upgradeMemos(spendInfo, this.currencyInfo) if ( spendInfo.spendTargets.length === 0 || spendInfo.spendTargets[0].publicAddress == null @@ -386,7 +388,9 @@ export class PolkadotEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo if (edgeSpendInfo.spendTargets.length !== 1) { throw new Error('Error: only one output allowed') @@ -487,7 +491,7 @@ export class PolkadotEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, - memos: [], + memos, nativeAmount: mul(totalTxAmount, '-1'), networkFee: nativeNetworkFee, otherParams, diff --git a/src/polkadot/info/polkadotInfo.ts b/src/polkadot/info/polkadotInfo.ts index 55ec060ed..9cf212dca 100644 --- a/src/polkadot/info/polkadotInfo.ts +++ b/src/polkadot/info/polkadotInfo.ts @@ -30,6 +30,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // No memo support: + memoOptions: [], + // Deprecated: defaultSettings: {}, metaTokens: [] diff --git a/src/ripple/RippleEngine.ts b/src/ripple/RippleEngine.ts index eee216d0c..99b896a24 100644 --- a/src/ripple/RippleEngine.ts +++ b/src/ripple/RippleEngine.ts @@ -27,6 +27,7 @@ import { JsonObject, NoAmountSpecifiedError } from 'edge-core-js/types' +import { base16 } from 'rfc4648' import { getBalanceChanges, OfferCreate, @@ -43,18 +44,14 @@ import { validatePayment } from 'xrpl/dist/npm/models/transactions/payment' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' import { getTokenIdFromCurrencyCode } from '../common/tokenHelpers' +import { upgradeMemos } from '../common/upgradeMemos' +import { utf8 } from '../common/utf8' import { cleanTxLogs, getOtherParams, matchJson, safeErrorMessage } from '../common/utils' -import { - PluginError, - pluginErrorCodes, - pluginErrorLabels, - pluginErrorName -} from '../pluginError' import { DIVIDE_PRECISION, EST_BLOCK_TIME_MS } from './rippleInfo' import { RippleTools } from './RippleTools' import { @@ -586,6 +583,7 @@ export class XrpEngine extends CurrencyEngine< } async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise { + spendInfo = upgradeMemos(spendInfo, this.currencyInfo) const { currencyCode } = spendInfo let spendableBalance = this.getBalance({ currencyCode @@ -602,8 +600,11 @@ export class XrpEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode, nativeBalance } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo + const parentCurrencyCode = this.currencyInfo.currencyCode // Activation Transaction: @@ -635,7 +636,7 @@ export class XrpEngine extends CurrencyEngine< currencyCode: this.currencyInfo.currencyCode, date: Date.now() / 1000, isSend: true, - memos: [], + memos, metadata: edgeSpendInfo.metadata, nativeAmount: `-${networkFee}`, networkFee, @@ -692,44 +693,6 @@ export class XrpEngine extends CurrencyEngine< } } - const uniqueIdentifier = - edgeSpendInfo.spendTargets[0].memo ?? - edgeSpendInfo.spendTargets[0].uniqueIdentifier ?? - edgeSpendInfo.spendTargets[0].otherParams?.uniqueIdentifier ?? - '' - - if (uniqueIdentifier !== '') { - // Destination Tag Checks - const { memoMaxLength = Infinity, memoMaxValue } = this.currencyInfo - - if (Number.isNaN(parseInt(uniqueIdentifier))) { - throw new PluginError( - 'Please enter a valid Destination Tag', - pluginErrorName.XRP_ERROR, - pluginErrorCodes[0], - pluginErrorLabels.UNIQUE_IDENTIFIER_FORMAT - ) - } - - if (uniqueIdentifier.length > memoMaxLength) { - throw new PluginError( - `Destination Tag must be ${memoMaxLength} characters or less`, - pluginErrorName.XRP_ERROR, - pluginErrorCodes[0], - pluginErrorLabels.UNIQUE_IDENTIFIER_EXCEEDS_LENGTH - ) - } - - if (memoMaxValue != null && gt(uniqueIdentifier, memoMaxValue)) { - throw new PluginError( - 'XRP Destination Tag is above its maximum limit', - pluginErrorName.XRP_ERROR, - pluginErrorCodes[0], - pluginErrorLabels.UNIQUE_IDENTIFIER_EXCEEDS_LIMIT - ) - } - } - let payment: PaymentJson if (currencyCode === parentCurrencyCode) { payment = { @@ -769,8 +732,18 @@ export class XrpEngine extends CurrencyEngine< nativeAmount = `-${nativeAmount}` } - if (uniqueIdentifier !== '') { - payment.DestinationTag = parseInt(uniqueIdentifier) + for (const memo of memos) { + if (memo.type === 'number') { + payment.DestinationTag = parseInt(memos[0].value) + } else if (memo.type === 'text') { + if (payment.Memos == null) payment.Memos = [] + payment.Memos.push({ + Memo: { + MemoFormat: base16.stringify(utf8.parse('text/plain')), + MemoData: base16.stringify(utf8.parse(memo.value)) + } + }) + } } const otherParams: XrpParams = { diff --git a/src/ripple/rippleInfo.ts b/src/ripple/rippleInfo.ts index c11d6d329..40d496e6d 100644 --- a/src/ripple/rippleInfo.ts +++ b/src/ripple/rippleInfo.ts @@ -32,10 +32,19 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + memoOptions: [ + // https://xrpl.org/payment.html#payment-fields + { type: 'number', memoName: 'destination tag', maxValue: '4294967295' }, + // https://xrpl.org/transaction-common-fields.html#memos-field + { type: 'text', memoName: 'memo', maxLength: 990 } + ], + multipleMemos: true, + // Deprecated: defaultSettings: {}, memoMaxLength: 10, memoMaxValue: '4294967295', + memoType: 'number', metaTokens: [] } diff --git a/src/solana/SolanaEngine.ts b/src/solana/SolanaEngine.ts index 8451b70c9..e424ffa43 100644 --- a/src/solana/SolanaEngine.ts +++ b/src/solana/SolanaEngine.ts @@ -16,6 +16,8 @@ import { base16 } from 'rfc4648' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' +import { utf8 } from '../common/utf8' import { asyncWaterfall, cleanTxLogs, @@ -315,7 +317,9 @@ export class SolanaEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo if (edgeSpendInfo.spendTargets.length !== 1) { throw new Error('Error: only one output allowed') @@ -349,8 +353,7 @@ export class SolanaEngine extends CurrencyEngine< }) ) - const memo = edgeSpendInfo.spendTargets[0]?.otherParams?.uniqueIdentifier - if (memo != null && memo !== '') { + if (memos[0]?.type === 'text') { const memoOpts = new TransactionInstruction({ keys: [ { @@ -360,7 +363,7 @@ export class SolanaEngine extends CurrencyEngine< } ], programId: new PublicKey(this.networkInfo.memoPublicKey), - data: Buffer.from(memo) + data: Buffer.from(utf8.parse(memos[0].value)) }) solTx.add(memoOpts) } @@ -379,7 +382,7 @@ export class SolanaEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, - memos: [], + memos, nativeAmount: mul(totalTxAmount, '-1'), networkFee: nativeNetworkFee, otherParams, diff --git a/src/solana/solanaInfo.ts b/src/solana/solanaInfo.ts index 2cd322d9c..3c338f4f3 100644 --- a/src/solana/solanaInfo.ts +++ b/src/solana/solanaInfo.ts @@ -34,8 +34,12 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // https://spl.solana.com/memo + memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 32 }], + // Deprecated: defaultSettings: {}, + memoType: 'text', metaTokens: [] } diff --git a/src/stellar/StellarEngine.ts b/src/stellar/StellarEngine.ts index 3bdf90efc..89f029274 100644 --- a/src/stellar/StellarEngine.ts +++ b/src/stellar/StellarEngine.ts @@ -14,6 +14,7 @@ import stellarApi, { Transaction } from 'stellar-sdk' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { asyncWaterfall, cleanTxLogs, @@ -470,8 +471,10 @@ export class StellarEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) const { edgeSpendInfo, currencyCode, nativeBalance, denom } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo if (edgeSpendInfo.spendTargets.length !== 1) { throw new Error('Error: only one output allowed') @@ -508,11 +511,6 @@ export class StellarEngine extends CurrencyEngine< this.walletLocalData.publicKey, this.otherData.accountSequence ) - const spendTarget0 = edgeSpendInfo.spendTargets[0] - const memoId: string | undefined = - spendTarget0.memo ?? - spendTarget0.uniqueIdentifier ?? - spendTarget0.otherParams?.uniqueIdentifier const feeSetting = edgeSpendInfo.networkFeeOption !== undefined && @@ -540,9 +538,18 @@ export class StellarEngine extends CurrencyEngine< }) ) } - if (memoId != null) { - const memo = stellarApi.Memo.id(memoId) - txBuilder = txBuilder.addMemo(memo) + for (const memo of memos) { + switch (memo.type) { + case 'hex': + txBuilder = txBuilder.addMemo(stellarApi.Memo.hash(memo.value)) + break + case 'number': + txBuilder = txBuilder.addMemo(stellarApi.Memo.id(memo.value)) + break + case 'text': + txBuilder = txBuilder.addMemo(stellarApi.Memo.text(memo.value)) + break + } } const transaction = txBuilder.build() @@ -560,7 +567,7 @@ export class StellarEngine extends CurrencyEngine< currencyCode, // currencyCode date: 0, // date isSend: nativeAmount.startsWith('-'), - memos: [], + memos, nativeAmount, // nativeAmount networkFee, // networkFee otherParams: { diff --git a/src/stellar/stellarInfo.ts b/src/stellar/stellarInfo.ts index c33d13027..7d60891bc 100644 --- a/src/stellar/stellarInfo.ts +++ b/src/stellar/stellarInfo.ts @@ -27,9 +27,19 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // https://developers.stellar.org/docs/encyclopedia/memos + memoOptions: [ + { type: 'text', maxLength: 28 }, + { type: 'number', maxValue: '18446744073709551615' }, + { type: 'hex', maxBytes: 32, minBytes: 32 } + // We also support a transaction ID for returned funds + ], + multipleMemos: true, + // Deprecated: defaultSettings: {}, memoMaxLength: 19, + memoType: 'text', metaTokens: [] } diff --git a/src/tezos/TezosEngine.ts b/src/tezos/TezosEngine.ts index 2a73d208c..5c68064f4 100644 --- a/src/tezos/TezosEngine.ts +++ b/src/tezos/TezosEngine.ts @@ -14,6 +14,7 @@ import { eztz } from 'eztz.js' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { asyncWaterfall, cleanTxLogs, @@ -398,6 +399,7 @@ export class TezosEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) return await makeSpendMutex( async () => await this.makeSpendInner(edgeSpendInfoIn) ) @@ -408,6 +410,8 @@ export class TezosEngine extends CurrencyEngine< ): Promise { const { edgeSpendInfo, currencyCode, nativeBalance, denom } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo + if (edgeSpendInfo.spendTargets.length !== 1) { throw new Error('Error: only one output allowed') } @@ -469,7 +473,7 @@ export class TezosEngine extends CurrencyEngine< currencyCode, date: 0, isSend: nativeAmount.startsWith('-'), - memos: [], + memos, nativeAmount, networkFee, otherParams: { diff --git a/src/tezos/tezosInfo.ts b/src/tezos/tezosInfo.ts index 3cec55a0e..8332e042f 100644 --- a/src/tezos/tezosInfo.ts +++ b/src/tezos/tezosInfo.ts @@ -53,6 +53,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // No memo support: + memoOptions: [], + // Deprecated: defaultSettings: {}, metaTokens: [] diff --git a/src/tron/TronEngine.ts b/src/tron/TronEngine.ts index f9b6b24f1..1c3faa9d3 100644 --- a/src/tron/TronEngine.ts +++ b/src/tron/TronEngine.ts @@ -17,6 +17,7 @@ import TronWeb from 'tronweb' import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { asyncWaterfall, getDenomination, @@ -1261,6 +1262,8 @@ export class TronEngine extends CurrencyEngine { } async getMaxSpendable(spendInfo: EdgeSpendInfo): Promise { + spendInfo = upgradeMemos(spendInfo, this.currencyInfo) + const { memos = [] } = spendInfo const balance = this.getBalance({ currencyCode: spendInfo.currencyCode }) @@ -1269,8 +1272,8 @@ export class TronEngine extends CurrencyEngine { throw new Error('Error: only one output allowed') } - const { publicAddress, memo } = spendInfo.spendTargets[0] - const note = memo === '' ? undefined : memo + const { publicAddress } = spendInfo.spendTargets[0] + const note = memos[0]?.type === 'text' ? memos[0].value : undefined if (publicAddress == null || spendInfo.currencyCode == null) { throw new Error('Error: need recipient address and/or currencyCode') @@ -1327,6 +1330,8 @@ export class TronEngine extends CurrencyEngine { } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) + // Check for other transaction types first if (edgeSpendInfoIn.otherParams != null) { let action: @@ -1348,6 +1353,7 @@ export class TronEngine extends CurrencyEngine { const { edgeSpendInfo, currencyCode } = super.makeSpendCheck( edgeSpendInfoIn ) + const { memos = [] } = edgeSpendInfo const isTokenTransfer = currencyCode !== this.currencyInfo.currencyCode @@ -1356,7 +1362,7 @@ export class TronEngine extends CurrencyEngine { throw new Error('Error: only one output allowed') } - const { nativeAmount, publicAddress, otherParams, memo } = + const { nativeAmount, publicAddress, otherParams } = edgeSpendInfo.spendTargets[0] if (publicAddress == null) throw new Error('makeSpend Missing publicAddress') @@ -1371,7 +1377,7 @@ export class TronEngine extends CurrencyEngine { ? this.allTokens.find(token => token.currencyCode === currencyCode) : undefined - const note = memo === '' ? undefined : memo + const note = memos[0]?.type === 'text' ? memos[0].value : undefined const txTransferParams: TronTransferParams = { currencyCode, @@ -1436,7 +1442,7 @@ export class TronEngine extends CurrencyEngine { currencyCode, // currencyCode date: 0, // date isSend: true, - memos: [], + memos, nativeAmount: mul(edgeNativeAmount, '-1'), // nativeAmount networkFee, // networkFee otherParams: txOtherParams, // otherParams diff --git a/src/tron/tronInfo.ts b/src/tron/tronInfo.ts index db11d309b..004bec754 100644 --- a/src/tron/tronInfo.ts +++ b/src/tron/tronInfo.ts @@ -127,6 +127,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // https://developers.tron.network/v3.7/docs/how-to-build-a-transaction-locally + memoOptions: [{ type: 'text', memoName: 'data', maxLength: 10 }], + // Deprecated: defaultSettings: {}, memoType: 'text', diff --git a/src/zcash/ZcashEngine.ts b/src/zcash/ZcashEngine.ts index 6bbfe4961..d66fa67e4 100644 --- a/src/zcash/ZcashEngine.ts +++ b/src/zcash/ZcashEngine.ts @@ -12,6 +12,7 @@ import { import { CurrencyEngine } from '../common/CurrencyEngine' import { PluginEnvironment } from '../common/innerPlugin' +import { upgradeMemos } from '../common/upgradeMemos' import { cleanTxLogs } from '../common/utils' import { ZcashTools } from './ZcashTools' import { @@ -301,8 +302,10 @@ export class ZcashEngine extends CurrencyEngine< } async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise { + edgeSpendInfoIn = upgradeMemos(edgeSpendInfoIn, this.currencyInfo) if (!this.isSynced()) throw new Error('Cannot spend until wallet is synced') const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn) + const { memos = [] } = edgeSpendInfo const spendTarget = edgeSpendInfo.spendTargets[0] const { publicAddress, nativeAmount } = spendTarget @@ -338,7 +341,7 @@ export class ZcashEngine extends CurrencyEngine< currencyCode, date: 0, isSend: true, - memos: [], + memos, nativeAmount: txNativeAmount, networkFee: this.networkInfo.defaultNetworkFee, ourReceiveAddresses: [], @@ -359,6 +362,7 @@ export class ZcashEngine extends CurrencyEngine< edgeTransaction: EdgeTransaction, opts?: EdgeEnginePrivateKeyOptions ): Promise { + const { memos } = edgeTransaction const zcashPrivateKeys = asZcashPrivateKeys(this.pluginId)( opts?.privateKeys ) @@ -368,6 +372,7 @@ export class ZcashEngine extends CurrencyEngine< ) throw new Error('Invalid spend targets') + const memo = memos[0]?.type === 'text' ? memos[0].value : '' const spendTarget = edgeTransaction.spendTargets[0] const txParams: ZcashSpendInfo = { zatoshi: sub( @@ -375,7 +380,7 @@ export class ZcashEngine extends CurrencyEngine< edgeTransaction.networkFee ), toAddress: spendTarget.publicAddress, - memo: spendTarget.memo ?? spendTarget.uniqueIdentifier ?? '', + memo, fromAccountIndex: 0, spendingKey: zcashPrivateKeys.spendKey } diff --git a/src/zcash/piratechainInfo.ts b/src/zcash/piratechainInfo.ts index ce0f4b797..900187d8b 100644 --- a/src/zcash/piratechainInfo.ts +++ b/src/zcash/piratechainInfo.ts @@ -38,6 +38,9 @@ const currencyInfo: EdgeCurrencyInfo = { } ], + // Copied from Zcash: + memoOptions: [{ type: 'text', maxLength: 512 }], + // Deprecated: defaultSettings: {}, metaTokens: [] diff --git a/src/zcash/zcashInfo.ts b/src/zcash/zcashInfo.ts index b0d833b71..487a16788 100644 --- a/src/zcash/zcashInfo.ts +++ b/src/zcash/zcashInfo.ts @@ -37,6 +37,9 @@ export const currencyInfo: EdgeCurrencyInfo = { } ], + // https://zips.z.cash/zip-0302 + memoOptions: [{ type: 'text', maxLength: 512 }], + // Deprecated: defaultSettings: {}, metaTokens: [] From d70e4609902f9b25936f03a8667ac9cfe586216f Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 24 Aug 2023 09:07:59 -0700 Subject: [PATCH 7/8] Return on-chain memos from algorand --- src/algorand/AlgorandEngine.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/algorand/AlgorandEngine.ts b/src/algorand/AlgorandEngine.ts index 764d0b511..f7af2514c 100644 --- a/src/algorand/AlgorandEngine.ts +++ b/src/algorand/AlgorandEngine.ts @@ -14,6 +14,7 @@ import { EdgeEngineActivationOptions, EdgeEngineGetActivationAssetsOptions, EdgeGetActivationAssetsResults, + EdgeMemo, EdgeSpendInfo, EdgeToken, EdgeTransaction, @@ -243,12 +244,13 @@ export class AlgorandEngine extends CurrencyEngine< processAlgorandTransaction(tx: BaseTransaction): void { const { - fee, 'confirmed-round': confirmedRound, - id, 'round-time': roundTime, - sender, - 'tx-type': txType + 'tx-type': txType, + fee, + id, + note, + sender } = tx let currencyCode: string @@ -332,12 +334,30 @@ export class AlgorandEngine extends CurrencyEngine< } } + const memos: EdgeMemo[] = [] + if (note != null) { + const data = base64.parse(note) + try { + memos.push({ + memoName: 'note', + type: 'text', + value: utf8.stringify(data) + }) + } catch (e) { + memos.push({ + memoName: 'note', + type: 'hex', + value: base16.stringify(data).toLowerCase() + }) + } + } + const edgeTransaction: EdgeTransaction = { blockHeight: confirmedRound, currencyCode, date: roundTime, isSend, - memos: [], + memos, nativeAmount, networkFee, ourReceiveAddresses, From 4b625849a732b0c97b919ccfb168f087fa5ce46b Mon Sep 17 00:00:00 2001 From: William Swanson Date: Wed, 30 Aug 2023 12:51:32 -0700 Subject: [PATCH 8/8] Support 0x prefixes in legacy memos --- src/common/upgradeMemos.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/upgradeMemos.ts b/src/common/upgradeMemos.ts index e464da271..4f3514c90 100644 --- a/src/common/upgradeMemos.ts +++ b/src/common/upgradeMemos.ts @@ -36,6 +36,11 @@ export function upgradeMemos( } } + // We need to support 0x prefixes for backwards compatibility: + for (const memo of legacyMemos) { + if (memo.type === 'hex') memo.value = memo.value.replace(/^0x/i, '') + } + // If we don't have modern memos, use the legacy ones: const out: EdgeSpendInfo = { ...spendInfo,