From 6baa3cbffabda6568969c122341920cc31d01f1b Mon Sep 17 00:00:00 2001 From: Jon Tzeng Date: Thu, 25 Jul 2024 13:56:44 -0700 Subject: [PATCH] Downgrade FIO back to v1.8.0 --- CHANGELOG.md | 2 + package.json | 2 +- src/fio/FioEngine.ts | 144 ++++++++++++++++--------------------------- src/fio/fioSchema.ts | 17 +++-- src/fio/fioTypes.ts | 3 +- yarn.lock | 28 +++------ 6 files changed, 73 insertions(+), 123 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f000298..0581f8ba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- changed: FIO SDK downgraded back to v1.8.0, pending stability fixes + ## 4.15.0 (2024-07-22) - added: (Solana/Ethereum) Add optional `lightMode` support to disable transaction query diff --git a/package.json b/package.json index f58ce87ad..f77fadea2 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "@emurgo/cardano-serialization-lib-nodejs": "^11.5.0", "@ethereumjs/common": "^4.0.0", "@ethereumjs/tx": "^5.0.0", - "@fioprotocol/fiosdk": "https://github.com/peachbits/fiosdk_typescript.git#458cc706fe2601caeaf5dc726a72bcdc12f41fc6", + "@fioprotocol/fiosdk": "https://github.com/peachbits/fiosdk_typescript.git#d04449fff9f9b8c1487359a5b6bf64b7b53d0b6b", "@greymass/eosio": "^0.6.8", "@greymass/eosio-resources": "^0.7.0", "@hashgraph/sdk": "^2.44.0", diff --git a/src/fio/FioEngine.ts b/src/fio/FioEngine.ts index 0bb05b0c8..1addd7614 100644 --- a/src/fio/FioEngine.ts +++ b/src/fio/FioEngine.ts @@ -1,7 +1,6 @@ import { FIOSDK } from '@fioprotocol/fiosdk' import { BalanceResponse } from '@fioprotocol/fiosdk/lib/entities/BalanceResponse' import { EndPoint } from '@fioprotocol/fiosdk/lib/entities/EndPoint' -import { GetEncryptKeyResponse } from '@fioprotocol/fiosdk/lib/entities/GetEncryptKeyResponse' import { GetObtData, PendingFioRequests, @@ -9,7 +8,6 @@ import { } from '@fioprotocol/fiosdk/lib/transactions/queries' import { Query } from '@fioprotocol/fiosdk/lib/transactions/queries/Query' import { Transactions } from '@fioprotocol/fiosdk/lib/transactions/Transactions' -import AbortController from 'abort-controller' import { add, div, gt, lt, lte, max, mul, sub } from 'biggystring' import { asMaybe, asString, asTuple } from 'cleaners' import { @@ -68,9 +66,8 @@ import { import { fioApiErrorCodes, FioError } from './fioError' import { asFioHistoryNodeAction, - asGetFioAddress, asGetFioBalanceResponse, - asGetFioDomains, + asGetFioName, asHistoryResponse, FioHistoryNodeAction, FioTxName @@ -633,20 +630,13 @@ export class FioEngine extends CurrencyEngine { case 'getPendingFioRequests': case 'getSentFioRequests': { const { endpoint, body } = params - res = await fioSdk.transactions.executeCall({ - baseUrl: apiUrl, - endPoint: endpoint, - body: JSON.stringify(body), - signal: new AbortController().signal - }) + res = await fioSdk.transactions.executeCall( + endpoint, + JSON.stringify(body) + ) break } case 'getCurrencyBalance': { - // This is a fallback query for this chain bug - // https://fioprotocol.atlassian.net/wiki/spaces/DAO/pages/852688908/2024-02-07+Token+Locking+Issue+on+Unstake - // Only the balance of the wallet will be returned and staked amounts - // will appear as zero until the account is corrected. This can be - // removed once all affected accounts are fixed. const currencyBalRes = await this.fetchCors( `${apiUrl}chain/get_currency_balance`, { @@ -803,11 +793,6 @@ export class FioEngine extends CurrencyEngine { res = { fio_domains: [], fio_addresses: [] } } } else if (actionName === 'getCurrencyBalance') { - // This is a fallback query for this chain bug - // https://fioprotocol.atlassian.net/wiki/spaces/DAO/pages/852688908/2024-02-07+Token+Locking+Issue+on+Unstake - // Only the balance of the wallet will be returned and staked amounts will - // appear as zero until the account is corrected. This can be removed once - // all affected accounts are fixed. res = await promiseNy( this.networkInfo.apiUrls.map( async apiUrl => @@ -959,14 +944,16 @@ export class FioEngine extends CurrencyEngine { } // Fio Addresses - let isChanged = false try { - const result = asGetFioAddress( - await this.multicastServers('getFioAddresses', { + const result = asGetFioName( + await this.multicastServers('getFioNames', { fioPublicKey: this.walletInfo.keys.publicKey }) ) + + let isChanged = false let areAddressesChanged = false + let areDomainsChanged = false // check addresses if (result.fio_addresses.length !== this.otherData.fioAddresses.length) { @@ -995,7 +982,8 @@ export class FioEngine extends CurrencyEngine { for (const fioAddress of this.otherData.fioAddresses) { if ( result.fio_addresses.findIndex( - item => item.fio_address === fioAddress.name + (item: { fio_address: string }) => + item.fio_address === fioAddress.name ) < 0 ) { areAddressesChanged = true @@ -1003,30 +991,9 @@ export class FioEngine extends CurrencyEngine { } } } - - if (areAddressesChanged) { - isChanged = true - this.otherData.fioAddresses = result.fio_addresses.map( - fioAddress => ({ - name: fioAddress.fio_address, - bundledTxs: fioAddress.remaining_bundled_tx - }) - ) - } } - } catch (e: any) { - this.warn('checkAccountInnerLoop getFioAddresses error: ', e) - } - - try { - // Check domains - const result = asGetFioDomains( - await this.multicastServers('getFioDomains', { - fioPublicKey: this.walletInfo.keys.publicKey - }) - ) - let areDomainsChanged = false + // check domains if (result.fio_domains.length !== this.otherData.fioDomains.length) { areDomainsChanged = true } else { @@ -1054,7 +1021,8 @@ export class FioEngine extends CurrencyEngine { for (const fioDomain of this.otherData.fioDomains) { if ( result.fio_domains.findIndex( - item => item.fio_domain === fioDomain.name + (item: { fio_domain: string }) => + item.fio_domain === fioDomain.name ) < 0 ) { areDomainsChanged = true @@ -1064,19 +1032,35 @@ export class FioEngine extends CurrencyEngine { } } + if (areAddressesChanged) { + isChanged = true + this.otherData.fioAddresses = result.fio_addresses.map( + (fioAddress: { fio_address: any; remaining_bundled_tx: any }) => ({ + name: fioAddress.fio_address, + bundledTxs: fioAddress.remaining_bundled_tx + }) + ) + } + if (areDomainsChanged) { isChanged = true - this.otherData.fioDomains = result.fio_domains.map(fioDomain => ({ - name: fioDomain.fio_domain, - expiration: fioDomain.expiration, - isPublic: fioDomain.is_public === 1 - })) + this.otherData.fioDomains = result.fio_domains.map( + (fioDomain: { + fio_domain: any + expiration: any + is_public: number + }) => ({ + name: fioDomain.fio_domain, + expiration: fioDomain.expiration, + isPublic: fioDomain.is_public === 1 + }) + ) } + + if (isChanged) this.localDataDirty() } catch (e: any) { this.warn('checkAccountInnerLoop getFioNames error: ', e) } - - if (isChanged) this.localDataDirty() } async fetchEncryptedFioRequests( @@ -1206,19 +1190,6 @@ export class FioEngine extends CurrencyEngine { const fioPrivateKeys = asFioPrivateKeys(opts?.privateKeys) let isChanged = false - // TODO: v1.9 of the FIO sdk introduced a getEncyptKey prop to their - // checkFioRequests fn, though the SDK can still function without it. - // Whenever they require it or provide more information about what it even - // is, we should implement it. - const defaultGetEncryptKey = async ( - fioAddress: string - ): Promise => { - // Provide a default response or handle the fallback logic here - return { - encrypt_public_key: this.walletInfo.keys.publicKey // Use the public key as a fallback - } - } - const checkFioRequests = async ( type: FioRequestTypes, decoder: Query @@ -1226,43 +1197,33 @@ export class FioEngine extends CurrencyEngine { const encryptedReqs = await this.fetchEncryptedFioRequests(type, decoder) decoder.privateKey = fioPrivateKeys.fioKey decoder.publicKey = this.walletInfo.keys.publicKey - - const decryptedRequestRes: { requests: FioRequest[] } = - (await decoder.decrypt({ - requests: encryptedReqs - })) ?? { requests: [] } - const { requests } = decryptedRequestRes + const decryptedReqs: { requests: FioRequest[] } = decoder.decrypt({ + requests: encryptedReqs + }) ?? { requests: [] } if ( - this.fioRequestsListChanged(this.otherData.fioRequests[type], requests) + this.fioRequestsListChanged( + this.otherData.fioRequests[type], + decryptedReqs.requests + ) ) { - this.otherData.fioRequests[type] = [...requests] + this.otherData.fioRequests[type] = [...decryptedReqs.requests] isChanged = true } } await checkFioRequests( 'PENDING', - new PendingFioRequests({ - fioPublicKey: this.walletInfo.keys.publicKey, - getEncryptKey: defaultGetEncryptKey - }) + new PendingFioRequests(this.walletInfo.keys.publicKey) ) await checkFioRequests( 'SENT', - new SentFioRequests({ - fioPublicKey: this.walletInfo.keys.publicKey, - getEncryptKey: defaultGetEncryptKey - }) + new SentFioRequests(this.walletInfo.keys.publicKey) ) if (isChanged) this.localDataDirty() - const obtDecoder = new GetObtData({ - fioPublicKey: this.walletInfo.keys.publicKey, - getEncryptKey: defaultGetEncryptKey, - includeEncrypted: false - }) + const obtDecoder = new GetObtData(this.walletInfo.keys.publicKey) const encryptedObtData = await this.fetchEncryptedObtData( 'getObtData', obtDecoder @@ -1270,10 +1231,9 @@ export class FioEngine extends CurrencyEngine { obtDecoder.privateKey = fioPrivateKeys.fioKey obtDecoder.publicKey = this.walletInfo.keys.publicKey const decryptedObtData: { obt_data_records: ObtData[] } = - (await obtDecoder.decrypt({ - obt_data_records: encryptedObtData, - more: 0 - })) ?? { obt_data_records: [] } + obtDecoder.decrypt({ + obt_data_records: encryptedObtData + }) ?? { obt_data_records: [] } this.obtData = decryptedObtData.obt_data_records diff --git a/src/fio/fioSchema.ts b/src/fio/fioSchema.ts index ba739a8e8..7658ab1a5 100644 --- a/src/fio/fioSchema.ts +++ b/src/fio/fioSchema.ts @@ -8,22 +8,19 @@ import { asValue } from 'cleaners' -export const asGetFioAddress = asObject({ - fio_addresses: asArray( - asObject({ - fio_address: asString, - remaining_bundled_tx: asNumber - }) - ) -}) - -export const asGetFioDomains = asObject({ +export const asGetFioName = asObject({ fio_domains: asArray( asObject({ fio_domain: asString, expiration: asString, is_public: asNumber }) + ), + fio_addresses: asArray( + asObject({ + fio_address: asString, + remaining_bundled_tx: asNumber + }) ) }) diff --git a/src/fio/fioTypes.ts b/src/fio/fioTypes.ts index d9ea2fe53..b708597fa 100644 --- a/src/fio/fioTypes.ts +++ b/src/fio/fioTypes.ts @@ -3,7 +3,6 @@ import type { FioNamesResponse } from '@fioprotocol/fiosdk/lib/entities/FioNames import { asArray, asBoolean, - asEither, asMaybe, asNumber, asObject, @@ -169,7 +168,7 @@ export const asObtData = asObject({ payee_fio_address: asString, payer_fio_public_key: asString, payee_fio_public_key: asString, - content: asEither(asString, asObject({ token_code: asString })), + content: asString, fio_request_id: asNumber, status: asString, time_stamp: asString diff --git a/yarn.lock b/yarn.lock index 7fb43854d..86d036cb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -857,17 +857,16 @@ randombytes "^2.1.0" text-encoding "0.7.0" -"@fioprotocol/fiosdk@https://github.com/peachbits/fiosdk_typescript.git#458cc706fe2601caeaf5dc726a72bcdc12f41fc6": - version "1.9.0" - resolved "https://github.com/peachbits/fiosdk_typescript.git#458cc706fe2601caeaf5dc726a72bcdc12f41fc6" +"@fioprotocol/fiosdk@https://github.com/peachbits/fiosdk_typescript.git#d04449fff9f9b8c1487359a5b6bf64b7b53d0b6b": + version "1.8.0" + resolved "https://github.com/peachbits/fiosdk_typescript.git#d04449fff9f9b8c1487359a5b6bf64b7b53d0b6b" dependencies: "@fioprotocol/fiojs" "1.0.1" "@types/text-encoding" "0.0.35" - abort-controller "3.0.0" - bip39 "3.1.0" - hdkey "1.1.2" - validate "5.2.0" - wif "2.0.6" + bip39 "^3.0.2" + hdkey "^1.1.1" + validate "^5.1.0" + wif "^2.0.6" "@glennsl/bs-json@^4.0.0": version "4.0.0" @@ -2950,13 +2949,6 @@ bip32@^4.0.0: typeforce "^1.11.5" wif "^2.0.6" -bip39@3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.1.0.tgz#c55a418deaf48826a6ceb34ac55b3ee1577e18a3" - integrity sha512-c9kiwdk45Do5GL0vJMe7tS95VjCii65mYAH7DfWl3uW8AVzXKQVUm64i3hzVybBDMp9r7j9iNxR85+ul8MdN/A== - dependencies: - "@noble/hashes" "^1.2.0" - bip39@^3.0.2, bip39@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.0.4.tgz#5b11fed966840b5e1b8539f0f54ab6392969b2a0" @@ -5387,7 +5379,7 @@ hasown@^2.0.0, hasown@^2.0.1, hasown@^2.0.2: dependencies: function-bind "^1.1.2" -hdkey@1.1.1, hdkey@1.1.2: +hdkey@1.1.1, hdkey@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/hdkey/-/hdkey-1.1.1.tgz#c2b3bfd5883ff9529b72f2f08b28be0972a9f64a" integrity sha512-DvHZ5OuavsfWs5yfVJZestsnc3wzPvLWNk6c2nRUfo6X+OtxypGt20vDDf7Ba+MJzjL3KS1og2nw2eBbLCOUTA== @@ -8851,7 +8843,7 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -validate@5.2.0: +validate@^5.1.0: version "5.2.0" resolved "https://registry.yarnpkg.com/validate/-/validate-5.2.0.tgz#fe7355c1644092b67dd07731ad5716cb99f689a5" integrity sha512-pVADd6GfDT7bALYvvzhfHnfmxCDem2bG7lGY3mwHzY7ktMH/SaczoF+eKkGokQEdGKozkJvyuOiSfQEHXp4zIA== @@ -9112,7 +9104,7 @@ wide-align@1.1.3: dependencies: string-width "^1.0.2 || 2" -wif@2.0.6, wif@^2.0.6: +wif@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/wif/-/wif-2.0.6.tgz#08d3f52056c66679299726fade0d432ae74b4704" integrity sha1-CNP1IFbGZnkplyb63g1DKudLRwQ=