Skip to content

Commit

Permalink
fix handling of TransactionPayment.TransactionFeePaid in Karura/Acala
Browse files Browse the repository at this point in the history
  • Loading branch information
eldargab committed Sep 19, 2023
1 parent a7adae7 commit 6a0c4aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"changes": [
{
"packageName": "@subsquid/substrate-data",
"comment": "fix handling of `TransactionPayment.TransactionFeePaid` in Karura/Acala",
"type": "patch"
},
{
"packageName": "@subsquid/substrate-ingest",
"comment": "fix handling of `TransactionPayment.TransactionFeePaid` in Karura/Acala",
"type": "patch"
}
],
"packageName": "@subsquid/substrate-data"
}
15 changes: 12 additions & 3 deletions substrate/substrate-data/src/parsing/fee/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Event, Extrinsic} from '../../interfaces/data'
import {assertEvent, isEvent, UnexpectedEventType} from '../../types/util'
import {getFeeCalc} from './calc'
import {
AcalaTransactionFeePaid,
ExtrinsicFailed,
ExtrinsicSuccessLatest,
ExtrinsicSuccessLegacy,
Expand All @@ -20,9 +21,17 @@ export function setExtrinsicFeesFromPaidEvent(
for (let e of events) {
if (e.name == 'TransactionPayment.TransactionFeePaid') {
let extrinsic = extrinsics[assertNotNull(e.extrinsicIndex)]
assertEvent(runtime, TransactionFeePaid, e)
let actualFee = BigInt(e.args.actualFee)
let tip = BigInt(e.args.tip)
let actualFee: bigint
let tip: bigint
if (isEvent(runtime, TransactionFeePaid, e)) {
actualFee = BigInt(e.args.actualFee)
tip = BigInt(e.args.tip)
} else if (isEvent(runtime, AcalaTransactionFeePaid, e)) {
actualFee = BigInt(e.args.actualFee)
tip = BigInt(e.args.actualTip)
} else {
throw new Error('TransactionPayment.TransactionFeePaid event has unexpected type')
}
extrinsic.fee = actualFee - tip
extrinsic.tip = tip
}
Expand Down
6 changes: 6 additions & 0 deletions substrate/substrate-data/src/parsing/fee/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ export const TransactionFeePaid = struct({
actualFee: numeric(),
tip: numeric()
})


export const AcalaTransactionFeePaid = struct({
actualFee: numeric(),
actualTip: numeric()
})

0 comments on commit 6a0c4aa

Please sign in to comment.