-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track oracle transactions (#170)
* feat: set up oracle feed tracker * feat: set up oracle service and handler * fix: schema * fix: typo * fix: redundant to big int * fix: handler
- Loading branch information
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { SubstrateEvent } from '@subql/types' | ||
import { OracleFedEvent } from '../../helpers/types' | ||
import { errorHandler } from '../../helpers/errorHandler' | ||
import { OracleTransactionData, OracleTransactionService } from '../services/oracleTransactionService' | ||
|
||
export const handleOracleFed = errorHandler(_handleOracleFed) | ||
async function _handleOracleFed(event: SubstrateEvent<OracleFedEvent>) { | ||
const [feeder, key, value] = event.event.data | ||
logger.info(`Oracle feed: ${feeder.toString()} key: ${key.toString()} value: ${value.toString()}`) | ||
|
||
const oracleTxData: OracleTransactionData = { | ||
hash: event.extrinsic.extrinsic.hash.toString(), | ||
timestamp: event.block.timestamp, | ||
key: key.toString(), | ||
value: value.toBigInt(), | ||
} | ||
|
||
OracleTransactionService.init(oracleTxData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { OracleTransaction } from '../../types' | ||
|
||
export interface OracleTransactionData { | ||
readonly hash: string | ||
readonly timestamp: Date | ||
readonly key: string | ||
readonly value?: bigint | ||
} | ||
|
||
export class OracleTransactionService extends OracleTransaction { | ||
static init = (data: OracleTransactionData) => { | ||
const tx = new this( | ||
`${data.hash}-${data.timestamp.toString()}-${data.key.toString()}`, | ||
data.timestamp, | ||
data.key.toString(), | ||
data.value | ||
) | ||
|
||
tx.timestamp = data.timestamp ?? null | ||
tx.key = data.key ?? null | ||
tx.value = data.value ?? null | ||
|
||
return tx | ||
} | ||
} |