mirror of
https://github.com/pezkuwichain/pezkuwi-subquery.git
synced 2026-04-21 23:37:56 +00:00
2f1d6dd316
Replace npm aliases (@polkadot -> @pezkuwi) with direct @pezkuwi package imports. Add tsconfig path mappings to redirect @polkadot type references from @subql/types to @pezkuwi equivalents, enabling proper type resolution without installing @polkadot packages. Remove Polkadot ecosystem swap/bridge integrations (HydraDx, AssetConversion) as they're incompatible with Pezkuwi.
64 lines
1.3 KiB
TypeScript
64 lines
1.3 KiB
TypeScript
import { HistoryElement, Transfer } from "../types";
|
|
import { SubstrateEvent } from "@subql/types";
|
|
import {
|
|
blockNumber,
|
|
eventId,
|
|
calculateFeeAsString,
|
|
timestamp,
|
|
getEventData,
|
|
} from "./common";
|
|
|
|
export async function handleTransfer(event: SubstrateEvent): Promise<void> {
|
|
const [from, to, amount] = getEventData(event);
|
|
|
|
await createTransfer(
|
|
event,
|
|
from.toString(),
|
|
"-from",
|
|
from.toString(),
|
|
to.toString(),
|
|
amount.toString(),
|
|
);
|
|
await createTransfer(
|
|
event,
|
|
to.toString(),
|
|
"-to",
|
|
from.toString(),
|
|
to.toString(),
|
|
amount.toString(),
|
|
);
|
|
}
|
|
|
|
async function createTransfer(
|
|
event: SubstrateEvent,
|
|
address: string,
|
|
suffix: string,
|
|
from: string,
|
|
to: string,
|
|
amount: string,
|
|
): Promise<void> {
|
|
const transfer: Transfer = {
|
|
amount: amount,
|
|
from: from,
|
|
to: to,
|
|
fee: calculateFeeAsString(event.extrinsic, from),
|
|
eventIdx: event.idx,
|
|
success: true,
|
|
};
|
|
|
|
const element = new HistoryElement(
|
|
`${eventId(event)}${suffix}`,
|
|
blockNumber(event),
|
|
timestamp(event.block),
|
|
address,
|
|
);
|
|
|
|
if (event.extrinsic !== undefined) {
|
|
element.extrinsicHash = event.extrinsic.extrinsic.hash.toString();
|
|
element.extrinsicIdx = event.extrinsic.idx;
|
|
}
|
|
|
|
element.transfer = transfer;
|
|
await element.save();
|
|
}
|