Skip to content

Commit 05e71fe

Browse files
committed
Clean up SubQL runtime smoke fixes
1 parent 6f4a5b2 commit 05e71fe

6 files changed

Lines changed: 35 additions & 18 deletions

File tree

packages/chain-stats-subql/src/mappings/handleBlock.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export async function handleBlock(block: SubstrateBlock) {
2121

2222
logger.info(`start insert ${startIndex}, batch ${accountData.length}`);
2323

24-
if (accountData.length === 0) return;
25-
2624
for (const data of accountData) {
2725
const token = await getToken(data.token);
2826

@@ -38,7 +36,5 @@ export async function handleBlock(block: SubstrateBlock) {
3836
}
3937
}
4038

41-
42-
4339
await record.save();
4440
}

packages/chain-stats-subql/src/runtimePolyfills.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { TextDecoder, TextEncoder } from "util";
1+
import { TextDecoder as NodeTextDecoder, TextEncoder as NodeTextEncoder } from "util";
2+
3+
type RuntimeWithTextEncoding = typeof globalThis & {
4+
TextDecoder?: typeof NodeTextDecoder;
5+
TextEncoder?: typeof NodeTextEncoder;
6+
};
27

38
export const installRuntimePolyfills = () => {
4-
const runtime = globalThis as any;
9+
const runtime = globalThis as RuntimeWithTextEncoding;
510

611
if (typeof runtime.TextEncoder === "undefined") {
7-
runtime.TextEncoder = TextEncoder;
12+
runtime.TextEncoder = NodeTextEncoder;
813
}
914

1015
if (typeof runtime.TextDecoder === "undefined") {
11-
runtime.TextDecoder = TextDecoder;
16+
runtime.TextDecoder = NodeTextDecoder;
1217
}
1318
};
1419

packages/chain-stats-subql/src/utils/records.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isSystemAccount, getNativeCurrency, getTokenDecimals, isTokenEqual, getSystemAccountName } from '@acala-network/subql-utils'
1+
import { isSystemAccount, getNativeCurrency, getTokenDecimals, isTokenEqual } from '@acala-network/subql-utils'
22
import { stringToHex, u8aToHex } from '@polkadot/util'
33
import { decodeAddress } from '@polkadot/util-crypto'
44
import { Block, Token, Account, AccountBalance, DailyAccountBalance, HourAccountBalance, HourToken, DailyToken } from '../types/models'
@@ -131,8 +131,8 @@ export async function getAccountBalance(
131131
record.accountId = address
132132
record.tokenId = tokenName
133133

134-
let free = BigInt(0);
135-
let reserved = BigInt(0);
134+
const free = BigInt(0);
135+
const reserved = BigInt(0);
136136

137137
record.total = free + reserved
138138
record.free = free

packages/histories-subql/src/handlers/handleRequestedRedeem.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import { getAccount, getRequestedRedeem } from "../records";
44
import { getBlockHash, getBlockNumber, getBlockTimestamp } from "../utils/block";
55
import { getExtrinsicHashFromEvent } from "../utils/extrinsic";
66

7+
type BooleanCodec = {
8+
toString(): string;
9+
};
10+
711
export const handleRequestedRedeem = async (event: SubstrateEvent) => {
8-
const [address, liquid_amount, allow_fast_match] = event.event.data as unknown as [AccountId, Balance, any];
12+
const [address, liquidAmount, allowFastMatch] = event.event.data as unknown as [AccountId, Balance, BooleanCodec];
913
const account = await getAccount(address.toString());
1014

1115
const historyId = `${getBlockNumber(event.block)}-${event.idx.toString()}`;
1216
const history = await getRequestedRedeem(historyId);
1317
history.addressId = account.id;
14-
history.amount = BigInt(liquid_amount.toString());
15-
history.allowFastMatch = allow_fast_match.toString() === "true";
18+
history.amount = BigInt(liquidAmount.toString());
19+
history.allowFastMatch = allowFastMatch.toString() === "true";
1620
history.blockNumber = getBlockNumber(event.block);
1721
history.blockHash = getBlockHash(event.block);
1822
history.timestamp = getBlockTimestamp(event.block);

packages/histories-subql/src/runtimePolyfills.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { TextDecoder, TextEncoder } from "util";
1+
import { TextDecoder as NodeTextDecoder, TextEncoder as NodeTextEncoder } from "util";
2+
3+
type RuntimeWithTextEncoding = typeof globalThis & {
4+
TextDecoder?: typeof NodeTextDecoder;
5+
TextEncoder?: typeof NodeTextEncoder;
6+
};
27

38
export const installRuntimePolyfills = () => {
4-
const runtime = globalThis as any;
9+
const runtime = globalThis as RuntimeWithTextEncoding;
510

611
if (typeof runtime.TextEncoder === "undefined") {
7-
runtime.TextEncoder = TextEncoder;
12+
runtime.TextEncoder = NodeTextEncoder;
813
}
914

1015
if (typeof runtime.TextDecoder === "undefined") {
11-
runtime.TextDecoder = TextDecoder;
16+
runtime.TextDecoder = NodeTextDecoder;
1217
}
1318
};
1419

scripts/smoke-subql-images.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ docker run -d \
3232

3333
for _ in {1..30}; do
3434
if docker exec "${POSTGRES}" pg_isready -U postgres >/dev/null 2>&1; then
35+
postgres_ready=true
3536
break
3637
fi
3738

3839
sleep 1
3940
done
4041

42+
if [[ "${postgres_ready:-false}" != "true" ]]; then
43+
docker logs "${POSTGRES}" 2>&1 || true
44+
echo "postgres failed to become ready"
45+
exit 1
46+
fi
47+
4148
run_smoke() {
4249
local name="$1"
4350
local image="$2"

0 commit comments

Comments
 (0)