-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #854 from autonomys/feat/fix-accounts-sub-query
Fix Accounts Sub Query Node
- Loading branch information
Showing
30 changed files
with
2,616 additions
and
158 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
"subscan", | ||
"subspace", | ||
"subsquid", | ||
"taskboard", | ||
"typegen" | ||
] | ||
} | ||
|
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"subscan", | ||
"subspace", | ||
"subsquid", | ||
"taskboard", | ||
"typegen" | ||
] | ||
} |
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
20 changes: 20 additions & 0 deletions
20
indexers/db/metadata/databases/gemini_3h/tables/accounts_accounts.yaml
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,20 @@ | ||
table: | ||
name: accounts | ||
schema: accounts | ||
select_permissions: | ||
- role: user | ||
permission: | ||
columns: | ||
- _block_range | ||
- created_at | ||
- free | ||
- nonce | ||
- reserved | ||
- total | ||
- updated_at | ||
- account_id | ||
- id | ||
- _id | ||
filter: {} | ||
allow_aggregations: true | ||
comment: "" |
18 changes: 18 additions & 0 deletions
18
indexers/db/metadata/databases/gemini_3h/tables/accounts_balance_histories.yaml
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,18 @@ | ||
table: | ||
name: balance_histories | ||
schema: accounts | ||
select_permissions: | ||
- role: user | ||
permission: | ||
columns: | ||
- _block_range | ||
- created_at | ||
- free | ||
- reserved | ||
- total | ||
- account_id | ||
- id | ||
- _id | ||
filter: {} | ||
allow_aggregations: true | ||
comment: "" |
23 changes: 23 additions & 0 deletions
23
indexers/db/metadata/databases/gemini_3h/tables/accounts_transfers.yaml
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,23 @@ | ||
table: | ||
name: transfers | ||
schema: accounts | ||
select_permissions: | ||
- role: user | ||
permission: | ||
columns: | ||
- success | ||
- _block_range | ||
- created_at | ||
- fee | ||
- timestamp | ||
- value | ||
- event_id | ||
- extrinsic_id | ||
- from | ||
- id | ||
- to | ||
- date | ||
- _id | ||
filter: {} | ||
allow_aggregations: true | ||
comment: "" |
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
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,82 @@ | ||
import { Account, BalanceHistory, Transfer } from "../types"; | ||
import { dateEntry } from "./utils"; | ||
|
||
export async function createAndSaveAccountIfNotExists( | ||
accountId: string, | ||
blockNumber: bigint, | ||
nonce: bigint, | ||
free: bigint, | ||
reserved: bigint, | ||
total: bigint | ||
): Promise<Account> { | ||
const id = accountId.toLowerCase(); | ||
const accounts = await Account.getByAccountId(id); | ||
let account = accounts ? accounts[0] : undefined; | ||
if (!account) { | ||
account = Account.create({ | ||
id, | ||
accountId: id, | ||
nonce, | ||
free, | ||
reserved, | ||
total, | ||
...dateEntry(blockNumber), | ||
}); | ||
await account.save(); | ||
} | ||
return account; | ||
} | ||
|
||
export async function createAndSaveBalanceHistory( | ||
accountId: string, | ||
blockNumber: bigint, | ||
free: bigint, | ||
reserved: bigint, | ||
total: bigint | ||
): Promise<BalanceHistory> { | ||
const id = accountId.toLowerCase() + "-" + blockNumber.toString(); | ||
const balanceHistory = BalanceHistory.create({ | ||
id, | ||
accountId: accountId.toLowerCase(), | ||
free, | ||
reserved, | ||
total, | ||
createdAt: blockNumber, | ||
}); | ||
await balanceHistory.save(); | ||
return balanceHistory; | ||
} | ||
|
||
export async function createAndSaveTransfer( | ||
blockNumber: bigint, | ||
extrinsicId: string, | ||
eventId: string, | ||
from: string, | ||
to: string, | ||
value: bigint, | ||
fee: bigint, | ||
success: boolean, | ||
timestamp: bigint, | ||
date: Date | ||
): Promise<Transfer> { | ||
const id = blockNumber + "-" + extrinsicId.toLowerCase(); | ||
const transfers = await Transfer.getByExtrinsicId(id); | ||
let transfer = transfers ? transfers[0] : undefined; | ||
if (!transfer) { | ||
transfer = Transfer.create({ | ||
id, | ||
extrinsicId, | ||
eventId, | ||
from, | ||
to, | ||
value, | ||
fee, | ||
success, | ||
timestamp, | ||
date, | ||
createdAt: blockNumber, | ||
}); | ||
await transfer.save(); | ||
} | ||
return transfer; | ||
} |
Oops, something went wrong.