diff --git a/src/polkadot/PolkadotEngine.ts b/src/polkadot/PolkadotEngine.ts index ca73df6c9..b58f73deb 100644 --- a/src/polkadot/PolkadotEngine.ts +++ b/src/polkadot/PolkadotEngine.ts @@ -288,6 +288,19 @@ export class PolkadotEngine extends CurrencyEngine< block { number timestamp + extrinsics { + nodes { + hash + id + blockId + signerId + events { + nodes { + id + } + } + } + } } } pageInfo { @@ -328,10 +341,11 @@ export class PolkadotEngine extends CurrencyEngine< ) if (edgeTransaction != null) { if ( - this.findTransaction( - this.currencyInfo.currencyCode, - edgeTransaction.txid - ) !== -1 + this.transactionList[this.currencyInfo.currencyCode].find( + tx => + tx.txid === edgeTransaction.txid && + tx.confirmations === 'confirmed' + ) != null ) { hasNextPage = false break @@ -382,6 +396,19 @@ export class PolkadotEngine extends CurrencyEngine< block { number timestamp + extrinsics { + nodes { + hash + id + blockId + signerId + events { + nodes { + id + } + } + } + } } } pageInfo { @@ -422,7 +449,11 @@ export class PolkadotEngine extends CurrencyEngine< ) if (edgeTransaction != null) { if ( - this.findTransaction(currencyCode, edgeTransaction.txid) !== -1 + this.transactionList[currencyCode].find( + tx => + tx.txid === edgeTransaction.txid && + tx.confirmations === 'confirmed' + ) != null ) { hasNextPage = false break @@ -899,15 +930,28 @@ export interface LiberlandTxProcessingContext { tokenId: EdgeTokenId } +// Not quite collision-proof but good enough for now +const getHash = (tx: LiberlandTransfer): string => { + const id = tx.id + for (const node of tx.block.extrinsics.nodes) { + for (const event of node.events.nodes) { + if (event.id === id) { + return node.hash + } + } + } + throw new Error('No matching hash found') +} + export function processLiberlandTransaction( context: LiberlandTxProcessingContext, tx: LiberlandTransfer ): EdgeTransaction | undefined { - const { id, fromId, value, block } = tx + const { fromId, value, block, id: extrinsicId } = tx const { tokenId } = context const blockHeight = parseInt(block.number) - const date = new Date(block.timestamp).getTime() / 1000 // Convert timestamp to epoch seconds + const date = new Date(block.timestamp + 'Z').getTime() / 1000 // Convert timestamp to epoch seconds const ourReceiveAddresses = [] @@ -944,8 +988,13 @@ export function processLiberlandTransaction( ourReceiveAddresses, signedTx: '', tokenId, - txid: id, // Currently not a typical hashed txid, but a blockHeight-event - walletId: context.walletId + txid: getHash(tx), + walletId: context.walletId, + otherParams: { + // HACK: Liberland explorer can't search by hashed txid, so use the extrinsicId + explorerPath: + tokenId == null ? `transfer/${extrinsicId}` : `merit/${extrinsicId}` + } } return edgeTransaction } diff --git a/src/polkadot/info/liberlandInfo.ts b/src/polkadot/info/liberlandInfo.ts index eb6e0fc6a..c9e010ef4 100644 --- a/src/polkadot/info/liberlandInfo.ts +++ b/src/polkadot/info/liberlandInfo.ts @@ -30,7 +30,7 @@ const networkInfo: PolkadotNetworkInfo = { subscanQueryLimit: 100, partialFeeOffsetMultiplier: '2', lengthFeePerByte: '76800000', - liberlandScanUrl: undefined + liberlandScanUrl: 'https://archive.mainnet.liberland.org/' } const currencyInfo: EdgeCurrencyInfo = { @@ -41,8 +41,7 @@ const currencyInfo: EdgeCurrencyInfo = { // Explorers: addressExplorer: '', - transactionExplorer: - 'https://polkadot.js.org/apps/?rpc=wss%%3A%%2F%%2Fmainnet.liberland.org%%2F#/explorer/query/%s', + transactionExplorer: 'https://chainscan.mainnet.liberland.org/%s', denominations: [ { diff --git a/src/polkadot/info/liberlandTestnetInfo.ts b/src/polkadot/info/liberlandTestnetInfo.ts index 4cb51b9ee..854612dd5 100644 --- a/src/polkadot/info/liberlandTestnetInfo.ts +++ b/src/polkadot/info/liberlandTestnetInfo.ts @@ -38,8 +38,7 @@ const currencyInfo: EdgeCurrencyInfo = { // Explorers: addressExplorer: '', - transactionExplorer: - 'https://polkadot.js.org/apps/?rpc=wss%%3A%%2F%%2Ftestchain.liberland.org%%2F#/explorer/query/%s', + transactionExplorer: 'https://chainscan.mainnet.liberland.org/%s', denominations: [ { diff --git a/src/polkadot/polkadotTypes.ts b/src/polkadot/polkadotTypes.ts index 4753d46c8..a4e26a874 100644 --- a/src/polkadot/polkadotTypes.ts +++ b/src/polkadot/polkadotTypes.ts @@ -99,7 +99,24 @@ export const asLiberlandTransfer = asObject({ eventIndex: asNumber, block: asObject({ number: asString, - timestamp: asString + timestamp: asString, + extrinsics: asObject({ + nodes: asArray( + asObject({ + hash: asString, + // id + // blockId + // signerId + events: asObject({ + nodes: asArray( + asObject({ + id: asString + }) + ) + }) + }) + ) + }) }) }) export type LiberlandTransfer = ReturnType diff --git a/test/processLiberlandTransaction.test.ts b/test/processLiberlandTransaction.test.ts index f07bf1407..1d7656617 100644 --- a/test/processLiberlandTransaction.test.ts +++ b/test/processLiberlandTransaction.test.ts @@ -73,7 +73,21 @@ export const testCases: TestCase[] = [ value: '1000', block: { number: '100', - timestamp: '2023-01-01T00:00:00Z' + timestamp: '2023-01-01T00:00:00Z', + extrinsics: { + nodes: [ + { + hash: '0x789', + events: { + nodes: [ + { + id: '0x123' + } + ] + } + } + ] + } }, eventIndex: 0 } @@ -90,7 +104,7 @@ export const testCases: TestCase[] = [ ourReceiveAddresses: [], signedTx: '', tokenId: null, - txid: '0x123', + txid: '0x789', walletId: 'test-wallet-id' } }, @@ -110,13 +124,27 @@ export const testCases: TestCase[] = [ tokenId: null }, tx: { - id: '0x456', + id: '0x123', fromId: '0xjkl', toId: '0xghi', value: '2000', block: { number: '200', - timestamp: '2023-01-02T00:00:00Z' + timestamp: '2023-01-02T00:00:00Z', + extrinsics: { + nodes: [ + { + hash: '0x456', + events: { + nodes: [ + { + id: '0x123' + } + ] + } + } + ] + } }, eventIndex: 0 }