-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
634 additions
and
478 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,58 @@ | ||
import {run} from '@subsquid/batch-processor' | ||
import {DataSourceBuilder, assertNotNull} from '@subsquid/tron-stream' | ||
import {augmentBlock} from '@subsquid/tron-objects' | ||
import {DataSourceBuilder} from '@subsquid/tron-stream' | ||
import {TypeormDatabase} from '@subsquid/typeorm-store' | ||
import * as erc20 from './abi/erc20' | ||
import {Transfer} from './model' | ||
|
||
|
||
const CONTRACT = 'a614f803b6fd780986a42c78ec9c7f77e6ded13c' | ||
const TOPIC0 = 'ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' | ||
|
||
|
||
const dataSource = new DataSourceBuilder() | ||
.setHttpApi({ | ||
url: assertNotNull(process.env.TRON_HTTP_API) | ||
.setGateway('https://v2.archive.subsquid.io/network/tron-mainnet') | ||
.setBlockRange({from: 11322942, to: 11323358}) | ||
.addLog({ | ||
where: { | ||
address: [CONTRACT], | ||
topic0: [TOPIC0] | ||
}, | ||
include: { | ||
transaction: true | ||
} | ||
}) | ||
.includeAllBlocks() | ||
.build() | ||
|
||
|
||
const database = new TypeormDatabase() | ||
|
||
|
||
run(dataSource, database, async ctx => { | ||
for (let block of ctx.blocks) { | ||
console.log(block) | ||
let transfers: Transfer[] = [] | ||
|
||
let blocks = ctx.blocks.map(augmentBlock) | ||
|
||
for (let block of blocks) { | ||
for (let log of block.logs) { | ||
if (log.address == CONTRACT && log.topics[0] === TOPIC0) { | ||
log.topics = log.topics.map(t => '0x' + t) | ||
log.data = '0x' + log.data | ||
let {from, to, value} = erc20.events.Transfer.decode(log) | ||
let tx = log.getTransaction() | ||
|
||
transfers.push(new Transfer({ | ||
id: log.id, | ||
blockNumber: block.header.height, | ||
timestamp: new Date(block.header.timestamp), | ||
tx: tx.hash, | ||
from, | ||
to, | ||
amount: value | ||
})) | ||
} | ||
} | ||
} | ||
|
||
await ctx.store.insert(transfers) | ||
}) |
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,29 @@ | ||
{ | ||
"name": "@subsquid/tron-objects", | ||
"version": "0.0.0", | ||
"description": "Augmented Tron data model", | ||
"license": "GPL-3.0-or-later", | ||
"repository": "[email protected]:subsquid/squid.git", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "rm -rf lib && tsc" | ||
}, | ||
"dependencies": { | ||
"@subsquid/util-internal": "^3.2.0" | ||
}, | ||
"peerDependencies": { | ||
"@subsquid/tron-stream": "^0.0.0" | ||
}, | ||
"devDependencies": { | ||
"@subsquid/tron-stream": "^0.0.0", | ||
"@types/node": "^18.18.14", | ||
"typescript": "~5.3.2" | ||
} | ||
} |
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,11 @@ | ||
import * as base from '@subsquid/tron-stream' | ||
import {setUpRelations} from './relations' | ||
import * as types from './types' | ||
import {Block} from './items' | ||
|
||
|
||
export function augmentBlock<F extends base.FieldSelection>(src: base.Block<F>): types.Block<F> { | ||
let block = Block.fromPartial(src) | ||
setUpRelations(block) | ||
return block as unknown as types.Block<F> | ||
} |
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,2 @@ | ||
export * from './types' | ||
export * from './augment' |
Oops, something went wrong.