Skip to content

Commit

Permalink
fixup! Implement LLD tx history
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Nov 16, 2024
1 parent f542c86 commit e75f708
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 19 deletions.
67 changes: 58 additions & 9 deletions src/polkadot/PolkadotEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ export class PolkadotEngine extends CurrencyEngine<
block {
number
timestamp
extrinsics {
nodes {
hash
id
blockId
signerId
events {
nodes {
id
}
}
}
}
}
}
pageInfo {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -382,6 +396,19 @@ export class PolkadotEngine extends CurrencyEngine<
block {
number
timestamp
extrinsics {
nodes {
hash
id
blockId
signerId
events {
nodes {
id
}
}
}
}
}
}
pageInfo {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions src/polkadot/info/liberlandInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const networkInfo: PolkadotNetworkInfo = {
subscanQueryLimit: 100,
partialFeeOffsetMultiplier: '2',
lengthFeePerByte: '76800000',
liberlandScanUrl: undefined
liberlandScanUrl: 'https://archive.mainnet.liberland.org/'
}

const currencyInfo: EdgeCurrencyInfo = {
Expand All @@ -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: [
{
Expand Down
3 changes: 1 addition & 2 deletions src/polkadot/info/liberlandTestnetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
19 changes: 18 additions & 1 deletion src/polkadot/polkadotTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof asLiberlandTransfer>
Expand Down
36 changes: 32 additions & 4 deletions test/processLiberlandTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -90,7 +104,7 @@ export const testCases: TestCase[] = [
ourReceiveAddresses: [],
signedTx: '',
tokenId: null,
txid: '0x123',
txid: '0x789',
walletId: 'test-wallet-id'
}
},
Expand All @@ -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
}
Expand Down

0 comments on commit e75f708

Please sign in to comment.