Skip to content

Commit

Permalink
fix: store oracle transactions properly (#173)
Browse files Browse the repository at this point in the history
* feat: set up oracle feed tracker

* feat: set up oracle service and handler

* fix: schema

* fix: typo

* fix: redundant to big int

* fix: handler

* fix: handler definition

* fix: oracle pallet name

* fix: save oracle tx

* fix: oracle key
  • Loading branch information
hieronx authored May 30, 2024
1 parent c0889d5 commit c574188
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/mappings/handlers/oracleHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { OracleTransactionData, OracleTransactionService } from '../services/ora
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()}`)
logger.info(`Oracle feed: ${feeder.toString()} key: ${key.isin.toString()} value: ${value.toString()}`)

const oracleTxData: OracleTransactionData = {
hash: event.extrinsic.extrinsic.hash.toString(),
timestamp: event.block.timestamp,
key: key.toString(),
key: key.isin.toString(),
value: value.toBigInt(),
}

OracleTransactionService.init(oracleTxData)
const oracleTx = OracleTransactionService.init(oracleTxData)
await oracleTx.save()
}
7 changes: 1 addition & 6 deletions src/mappings/services/oracleTransactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export interface OracleTransactionData {

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
)
const tx = new this(`${data.hash}-${data.key.toString()}`, data.timestamp, data.key.toString(), data.value)

tx.timestamp = data.timestamp ?? null
tx.key = data.key ?? null
Expand Down

0 comments on commit c574188

Please sign in to comment.