diff --git a/package.json b/package.json index cb15243a..679102cd 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "base-x": "^4.0.0", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", - "edge-core-js": "^1.14.0", + "edge-core-js": "^2.5.0", "eslint": "^7.14.0", "eslint-config-standard-kit": "0.15.1", "eslint-plugin-import": "^2.22.1", diff --git a/src/common/utxobased/db/Processor.ts b/src/common/utxobased/db/Processor.ts index 90170e20..f35d7719 100644 --- a/src/common/utxobased/db/Processor.ts +++ b/src/common/utxobased/db/Processor.ts @@ -33,7 +33,12 @@ interface FetchTransactionArgs { blockHeight?: number blockHeightMax?: number txId?: string - options?: EdgeGetTransactionsOptions + options?: EdgeGetTransactionsOptions & { + endDate?: Date + startDate?: Date + startEntries?: number + startIndex?: number + } } interface FetchUtxosArgs { diff --git a/src/common/utxobased/engine/UtxoEngine.ts b/src/common/utxobased/engine/UtxoEngine.ts index bdab5eee..f5b1961f 100644 --- a/src/common/utxobased/engine/UtxoEngine.ts +++ b/src/common/utxobased/engine/UtxoEngine.ts @@ -3,7 +3,6 @@ import { asMaybe } from 'cleaners' import { makeMemoryDisklet } from 'disklet' import { DustSpendError, - EdgeCurrencyCodeOptions, EdgeCurrencyEngine, EdgeDataDump, EdgeFreshAddress, @@ -12,6 +11,7 @@ import { EdgePaymentProtocolInfo, EdgeSignMessageOptions, EdgeSpendInfo, + EdgeTokenIdOptions, EdgeTokenInfo, EdgeTransaction, InsufficientFundsError, @@ -367,7 +367,7 @@ export async function makeUtxoEngine( pluginState.removeEngine(engineState) }, - getBalance(_opts: EdgeCurrencyCodeOptions): string { + getBalance(_opts: EdgeTokenIdOptions): string { return metadata.state.balance }, @@ -463,7 +463,7 @@ export async function makeUtxoEngine( return await engineState.getFreshAddress({ forceIndex }) }, - getNumTransactions(_opts: EdgeCurrencyCodeOptions): number { + getNumTransactions(_opts: EdgeTokenIdOptions): number { return processor.numTransactions() }, @@ -543,7 +543,7 @@ export async function makeUtxoEngine( bs.gt(totalAmountToSend, `${sumUtxos(utxos)}`) || utxos.length === 0 ) { - throw new InsufficientFundsError(currencyInfo.currencyCode) + throw new InsufficientFundsError({ tokenId: null }) } let targets: MakeTxTarget[] = [] @@ -949,7 +949,7 @@ export async function makeUtxoEngine( if (tmpUtxos === null || tmpUtxos.length < 1) { throw new Error('Private key has no funds') } - const destAddress = await this.getFreshAddress({}) + const destAddress = await this.getFreshAddress({ tokenId: null }) const nativeAmount = tmpMetadata.state.balance const txOptions: TxOptions = { utxos: tmpUtxos, subtractFee: true } spendInfo.spendTargets = [ diff --git a/src/common/utxobased/keymanager/keymanager.ts b/src/common/utxobased/keymanager/keymanager.ts index a6d68731..605c37ef 100644 --- a/src/common/utxobased/keymanager/keymanager.ts +++ b/src/common/utxobased/keymanager/keymanager.ts @@ -1078,7 +1078,7 @@ export function makeTx(args: MakeTxArgs): MakeTxReturn { // This is how much fee is needed to validate the spend const feeDelta = result.fee - (inputsValue - targetsValue) throw new InsufficientFundsErrorPlus({ - currencyCode: args.currencyCode, + tokenId: null, networkFee: result.fee.toString(), networkFeeShortage: feeDelta.toString() }) diff --git a/src/common/utxobased/keymanager/types.ts b/src/common/utxobased/keymanager/types.ts index c7fad49b..81ef731b 100644 --- a/src/common/utxobased/keymanager/types.ts +++ b/src/common/utxobased/keymanager/types.ts @@ -1,16 +1,17 @@ import { Cleaner } from 'cleaners' -import { InsufficientFundsError } from 'edge-core-js/types' +import { EdgeTokenId, InsufficientFundsError } from 'edge-core-js/types' interface InsufficientFundsErrorOptsPlus { // The currency we need more of: - currencyCode?: string + tokenId: EdgeTokenId // If we don't have enough funds for a token send: networkFee?: string + networkFeeShortage?: string } export class InsufficientFundsErrorPlus extends InsufficientFundsError { networkFeeShortage?: string - constructor(opts: InsufficientFundsErrorOptsPlus = {}) { + constructor(opts: InsufficientFundsErrorOptsPlus) { super(opts) const { networkFeeShortage } = opts this.networkFeeShortage = networkFeeShortage diff --git a/test/common/plugin/CurrencyPlugin.spec.ts b/test/common/plugin/CurrencyPlugin.spec.ts index 7b7e6bf9..9851e4c2 100644 --- a/test/common/plugin/CurrencyPlugin.spec.ts +++ b/test/common/plugin/CurrencyPlugin.spec.ts @@ -25,6 +25,7 @@ describe('currencyPlugins.spec', () => { const fakeIo = makeFakeIo() const pluginOpts: EdgeCorePluginOptions = { initOptions: {}, + infoPayload: {}, io: { ...fakeIo, random: () => Uint8Array.from(fixture.key) diff --git a/test/common/utxobased/db/Processor.spec.ts b/test/common/utxobased/db/Processor.spec.ts index 1cf5be58..676863d7 100644 --- a/test/common/utxobased/db/Processor.spec.ts +++ b/test/common/utxobased/db/Processor.spec.ts @@ -589,16 +589,25 @@ describe('Processor transactions tests', () => { expect(tx3?.ourIns[0]).to.eqls('0') expect(tx3?.ourAmount).to.eqls('1') - const [tx4] = await processor.fetchTransactions({ options: {} }) + const [tx4] = await processor.fetchTransactions({ + options: { + tokenId: null + } + }) expect(tx4).not.to.be.undefined const results = await processor.fetchTransactions({ - options: { startDate: new Date(11_000), endDate: new Date(15_000) } + options: { + tokenId: null, + startDate: new Date(11_000), + endDate: new Date(15_000) + } }) expect(results).to.deep.equal([]) const [tx6] = await processor.fetchTransactions({ options: { + tokenId: null, startDate: new Date(9_000), endDate: new Date(15_000) } @@ -693,11 +702,16 @@ describe('Processor transactions tests', () => { expect(tx3?.ourIns[0]).to.eqls('0') expect(tx3?.ourAmount).to.eqls('1') - const [tx4] = await processor.fetchTransactions({ options: {} }) + const [tx4] = await processor.fetchTransactions({ + options: { + tokenId: null + } + }) expect(tx4).not.to.be.undefined const [tx5] = await processor.fetchTransactions({ options: { + tokenId: null, startDate: new Date(11_000), endDate: new Date(20_000) } @@ -706,6 +720,7 @@ describe('Processor transactions tests', () => { const tx6 = await processor.fetchTransactions({ options: { + tokenId: null, startDate: new Date(9_000), endDate: new Date(21_000) } diff --git a/test/common/utxobased/engine/engine.fixtures/bitcoinTestnet/tests.ts b/test/common/utxobased/engine/engine.fixtures/bitcoinTestnet/tests.ts index 872de0e2..3a082af9 100644 --- a/test/common/utxobased/engine/engine.fixtures/bitcoinTestnet/tests.ts +++ b/test/common/utxobased/engine/engine.fixtures/bitcoinTestnet/tests.ts @@ -8,12 +8,12 @@ export interface SpendTests { } const Spend: SpendTests = { 'low fee': { + tokenId: null, networkFeeOption: 'low', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -26,12 +26,12 @@ const Spend: SpendTests = { ] }, 'low standard fee': { + tokenId: null, networkFeeOption: 'standard', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -40,12 +40,12 @@ const Spend: SpendTests = { ] }, 'middle standard fee': { + tokenId: null, networkFeeOption: 'standard', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -54,12 +54,12 @@ const Spend: SpendTests = { ] }, 'high standard fee': { + tokenId: null, networkFeeOption: 'standard', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -72,12 +72,12 @@ const Spend: SpendTests = { ] }, 'high fee': { + tokenId: null, networkFeeOption: 'high', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -90,13 +90,13 @@ const Spend: SpendTests = { ] }, 'custom fee': { + tokenId: null, networkFeeOption: 'custom', customNetworkFee: { satPerByte: '1000' }, metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -111,12 +111,12 @@ const Spend: SpendTests = { } const InsufficientFundsError: SpendTests = { 'an amount over the balance': { + tokenId: null, networkFeeOption: 'high', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -129,12 +129,12 @@ const InsufficientFundsError: SpendTests = { ] }, 'a really big amount': { + tokenId: null, networkFeeOption: 'high', metadata: { name: 'Transfer to College Fund', category: 'Transfer:Wallet:College Fund' }, - currencyCode: 'TESTBTC', spendTargets: [ { publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74', @@ -150,6 +150,7 @@ const InsufficientFundsError: SpendTests = { const Sweep: SpendTests = { 'low fee': { spendTargets: [], + tokenId: null, networkFeeOption: 'low', metadata: { name: 'Transfer to College Fund', @@ -159,6 +160,7 @@ const Sweep: SpendTests = { }, 'low standard fee': { spendTargets: [], + tokenId: null, networkFeeOption: 'low', metadata: { name: 'Transfer to College Fund', @@ -168,6 +170,7 @@ const Sweep: SpendTests = { }, 'high fee': { spendTargets: [], + tokenId: null, networkFeeOption: 'high', metadata: { name: 'Transfer to College Fund', @@ -177,6 +180,7 @@ const Sweep: SpendTests = { }, 'custom fee': { spendTargets: [], + tokenId: null, networkFeeOption: 'custom', customNetworkFee: { satPerByte: '1000' }, metadata: { diff --git a/test/common/utxobased/engine/engine.spec.ts b/test/common/utxobased/engine/engine.spec.ts index b5b9c0bf..e04c1f4b 100644 --- a/test/common/utxobased/engine/engine.spec.ts +++ b/test/common/utxobased/engine/engine.spec.ts @@ -11,7 +11,6 @@ import { EdgeCurrencyPlugin, EdgeCurrencyTools, EdgeFetchFunction, - EdgeGetTransactionsOptions, EdgeSpendInfo, JsonObject, makeFakeIo @@ -58,6 +57,7 @@ describe('engine.spec', function () { fetch: fetchHack }, log: testLog, + infoPayload: {}, nativeIo: {}, pluginDisklet: fakeIoDisklet } @@ -286,14 +286,14 @@ describe('engine.spec', function () { describe(`Get Transactions from Wallet type ${WALLET_TYPE}`, function () { it('Should get number of transactions from cache', function () { assert.equal( - engine.getNumTransactions({}), + engine.getNumTransactions({ tokenId: null }), TX_AMOUNT, `should have ${TX_AMOUNT} tx from cache` ) }) it('Should get transactions from cache', async function () { - await engine.getTransactions({}).then(txs => { + await engine.getTransactions({ tokenId: null }).then(txs => { assert.equal( txs.length, TX_AMOUNT, @@ -301,15 +301,6 @@ describe('engine.spec', function () { ) }) }) - - it('Should get transactions from cache with options', async function () { - const options: EdgeGetTransactionsOptions = { - startIndex: 1, - startEntries: 2 - } - const txs = await engine.getTransactions(options) - assert.equal(txs.length, 2, 'should have 2 tx from cache') - }) }) describe('Should Add Gap Limit Addresses', function () { @@ -419,6 +410,7 @@ describe('engine.spec', function () { it('Should fail since no spend target is given', async function () { const spendInfo: EdgeSpendInfo = { + tokenId: null, networkFeeOption: 'high', metadata: { name: 'Transfer to College Fund', diff --git a/yarn.lock b/yarn.lock index 7378f318..af3fbe9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3121,10 +3121,10 @@ ecc-jsbn@~0.1.1: typeforce "^1.18.0" wif "^2.0.6" -edge-core-js@^1.14.0: - version "1.14.0" - resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-1.14.0.tgz#16569cf6a24b50e26e0105eca554bd041ce15a01" - integrity sha512-P2yGTyu4eqoFUHFnrmkemxJrFFezql+cL2ZZ01JDyRJFgeAwy9zlEmg1Aj4IgOq8hzoNUFTd68fKTVPZZRDKEA== +edge-core-js@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-2.5.0.tgz#9dc013c4f59a7a3fb1c88880eb600c4ef3e44e4f" + integrity sha512-sY0lJDIECanLx/muNGRXz3BUcfd3c76gCFA2BZu/4coE2O5o5GK4QnNB64uKPw6XBNrLfDhP1IcrclHDDgcOUQ== dependencies: aes-js "^3.1.0" base-x "^4.0.0"