Skip to content

Commit

Permalink
Downgrade FIO back to v1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Jul 25, 2024
1 parent 10f9cc7 commit 6baa3cb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 123 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
144 changes: 52 additions & 92 deletions src/fio/FioEngine.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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,
SentFioRequests
} 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 {
Expand Down Expand Up @@ -68,9 +66,8 @@ import {
import { fioApiErrorCodes, FioError } from './fioError'
import {
asFioHistoryNodeAction,
asGetFioAddress,
asGetFioBalanceResponse,
asGetFioDomains,
asGetFioName,
asHistoryResponse,
FioHistoryNodeAction,
FioTxName
Expand Down Expand Up @@ -633,20 +630,13 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
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`,
{
Expand Down Expand Up @@ -803,11 +793,6 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
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 =>
Expand Down Expand Up @@ -959,14 +944,16 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
}

// 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) {
Expand Down Expand Up @@ -995,38 +982,18 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
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
break
}
}
}

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 {
Expand Down Expand Up @@ -1054,7 +1021,8 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
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
Expand All @@ -1064,19 +1032,35 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
}
}

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(
Expand Down Expand Up @@ -1206,74 +1190,50 @@ export class FioEngine extends CurrencyEngine<FioTools, SafeFioWalletInfo> {
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<GetEncryptKeyResponse> => {
// 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<PendingFioRequests | SentFioRequests>
): Promise<void> => {
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
)
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

Expand Down
17 changes: 7 additions & 10 deletions src/fio/fioSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
})

Expand Down
3 changes: 1 addition & 2 deletions src/fio/fioTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { FioNamesResponse } from '@fioprotocol/fiosdk/lib/entities/FioNames
import {
asArray,
asBoolean,
asEither,
asMaybe,
asNumber,
asObject,
Expand Down Expand Up @@ -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
Expand Down
28 changes: 10 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2950,13 +2949,6 @@ bip32@^4.0.0:
typeforce "^1.11.5"
wif "^2.0.6"

[email protected]:
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"
Expand Down Expand Up @@ -5387,7 +5379,7 @@ hasown@^2.0.0, hasown@^2.0.1, hasown@^2.0.2:
dependencies:
function-bind "^1.1.2"

[email protected], [email protected].2:
[email protected], 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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -9112,7 +9104,7 @@ [email protected]:
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=
Expand Down

0 comments on commit 6baa3cb

Please sign in to comment.