Comments (7)
Hi @zefir01
Would you mind to show your addCall/addEvent/etc handlers?
from squid-sdk.
all the usual...
import {lookupArchive} from "@subsquid/archive-registry"
import * as ss58 from "@subsquid/ss58"
import {BatchContext, BatchProcessorItem, SubstrateBatchProcessor} from "@subsquid/substrate-processor"
import {Store, TypeormDatabase} from "@subsquid/typeorm-store"
import {In} from "typeorm"
import {Account, HistoricalBalance} from "./model"
import {BalancesTransferEvent} from "./types/events"
import {decodeAddress} from '@polkadot/util-crypto';
import {u8aToHex} from '@polkadot/util';
const processor = new SubstrateBatchProcessor()
.setTypesBundle('polkadot')
.setBatchSize(1000)
//.setBlockRange({from: 11270865, to: 11270867})
.setDataSource({
// Lookup archive by the network name in the Subsquid registry
//archive: lookupArchive("polkadot", { release: "FireSquid" })
archive: 'https://blablabla.com/graphql',
//chain: 'wss://blablabla.com'
// Use archive created by archive/docker-compose.yml
// archive: 'http://localhost:8888/graphql'
})
.setPrometheusPort(9090)
.addEvent('Balances.Transfer', {
data: {event: {args: true}}
} as const)
type Item = BatchProcessorItem<typeof processor>
type Ctx = BatchContext<Store, Item>
const targetAccount = '1ENYhhP9K1ysJSoKrwVEiyD6XAY2w1eZANRJbRq597pkn3Q';
processor.run(new TypeormDatabase(), async ctx => {
let transfers = getTransfers(ctx).filter(p=>p.from===targetAccount || p.to===targetAccount);
let accountIds = new Set<string>();
for (let t of transfers) {
accountIds.add(t.from);
accountIds.add(t.to);
}
let accounts = await ctx.store.findBy(Account, {id: In([...accountIds])}).then(accounts => {
return new Map(accounts.map(a => [a.id, a]))
})
let history: HistoricalBalance[] = []
for (let t of transfers) {
let from = getAccount(accounts, t.from)
let to = getAccount(accounts, t.to)
from.balance -= t.amount
to.balance += t.amount
let balance=new HistoricalBalance({
id: t.id + "-from",
accountFrom: from,
accountTo: to,
balanceFrom: from.balance,
balanceTo: to.balance,
timestamp: t.timestamp
});
console.log(balance);
history.push(balance);
// history.push(new HistoricalBalance({
// id: t.id + "-to",
// account: to,
// balance: to.balance,
// timestamp: t.timestamp
// }))
}
await ctx.store.save(Array.from(accounts.values()))
await ctx.store.insert(history)
})
interface TransferEvent {
id: string
from: string
to: string
amount: bigint
timestamp: bigint
}
function getTransfers(ctx: Ctx): TransferEvent[] {
let transfers: TransferEvent[] = []
for (let block of ctx.blocks) {
for (let item of block.items) {
if (item.name == "Balances.Transfer") {
let e = new BalancesTransferEvent(ctx, item.event)
let rec: {from: Uint8Array, to: Uint8Array, amount: bigint}
if (e.isV1020) {
let [from, to, amount, ] = e.asV1020
rec = {from, to, amount}
} else if (e.isV1050) {
let [from, to, amount] = e.asV1050
rec = {from, to, amount}
} else {
rec = e.asV9130
}
transfers.push({
id: item.event.id,
from: ss58.codec('polkadot').encode(rec.from),
to: ss58.codec('polkadot').encode(rec.to),
amount: rec.amount,
timestamp: BigInt(block.header.timestamp)
})
}
}
}
return transfers
}
function getAccount(m: Map<string, Account>, id: string): Account {
let acc = m.get(id)
if (acc == null) {
acc = new Account()
acc.id = id
acc.balance = 0n
m.set(id, acc)
}
return acc
}
from squid-sdk.
This query shouldn't invoke full scan. Try to ping api:
curl -g -X POST -H "Content-Type: application/json" \
-d '{"query":"query { status { head } }"}' \
https://blablabla.com/graphql
from squid-sdk.
from squid-sdk.
It will not fix the problem but how about use subsquid hosted archive? - https://polkadot.archive.subsquid.io/graphql
from squid-sdk.
It is not safe. we work with money.
from squid-sdk.
We use a cockroach DB cluster in production and postgres is probably not a good fit for 1M+ blocks as it doesn't scale.
Can you pls elaborate on your concerns about "it's not safe"?
from squid-sdk.
Related Issues (20)
- FATAL sqd:substrate-typegen Error: Unknown signed extension: OnlyMigrator HOT 3
- typeorm-store Functionality Enhancements and ON CONFLICT Support for Store Operations HOT 1
- Null unsafety should be explained
- ethers.js: create typegen for ABIs
- ethers.js: Create custom decoder
- ethers.js: Benchark, compare with ethers & viem HOT 1
- ethers.js: Test with different ABIs
- Testing framework: RnD HOT 4
- Testing framework: PoC
- Typegen for storage slots
- Create a link tree of subsquid related links and include that on X (formerly Twitter) Bio for user safety.
- Invalid generation of TypeORM model for entity with nullable relation. HOT 4
- Experimental decorators: don't use them? HOT 1
- Processor crashed with missing blocks despite correct DB entries HOT 6
- Add l1 transaction fields to mapping schema
- PrimaryColumns other than 'id' are not supported in codegen HOT 1
- feature request: export typedefs for implementing your own store HOT 1
- request for tutorial
- Squid stops indexing blocks w/o any error HOT 1
- Make openreader compatible to The Graph HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from squid-sdk.