mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-10-25 04:55:03 +00:00
Rebrand: polkadot → pezkuwi, substrate → bizinikiwi, kusama → dicle
This commit is contained in:
commit
d5f038faea
1383 files changed
+1088018
No files matched your search
@@ -0,0 +1,53 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KeyringPair } from '@pezkuwi/keyring/types';
|
||||
import type { Registry, SignerPayloadJSON, SignerPayloadRaw } from '@pezkuwi/types/types';
|
||||
import type { Signer, SignerResult } from '../types/index.js';
|
||||
|
||||
import { hexToU8a, objectSpread, u8aToHex } from '@pezkuwi/util';
|
||||
|
||||
let id = 0;
|
||||
|
||||
export class SingleAccountSigner implements Signer {
|
||||
readonly #keyringPair: KeyringPair;
|
||||
readonly #registry: Registry;
|
||||
readonly #signDelay: number;
|
||||
|
||||
constructor (registry: Registry, keyringPair: KeyringPair, signDelay = 0) {
|
||||
this.#keyringPair = keyringPair;
|
||||
this.#registry = registry;
|
||||
this.#signDelay = signDelay;
|
||||
}
|
||||
|
||||
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
|
||||
if (payload.address !== this.#keyringPair.address) {
|
||||
throw new Error('Signer does not have the keyringPair');
|
||||
}
|
||||
|
||||
return new Promise((resolve): void => {
|
||||
setTimeout((): void => {
|
||||
const signed = this.#registry.createType('ExtrinsicPayload', payload, { version: payload.version }).sign(this.#keyringPair);
|
||||
|
||||
resolve(objectSpread({ id: ++id }, signed));
|
||||
}, this.#signDelay);
|
||||
});
|
||||
}
|
||||
|
||||
public async signRaw ({ address, data }: SignerPayloadRaw): Promise<SignerResult> {
|
||||
if (address !== this.#keyringPair.address) {
|
||||
throw new Error('Signer does not have the keyringPair');
|
||||
}
|
||||
|
||||
return new Promise((resolve): void => {
|
||||
setTimeout((): void => {
|
||||
const signature = u8aToHex(this.#keyringPair.sign(hexToU8a(data)));
|
||||
|
||||
resolve({
|
||||
id: ++id,
|
||||
signature
|
||||
});
|
||||
}, this.#signDelay);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './logEvents.js';
|
||||
export * from './SingleAccountSigner.js';
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { EventRecord } from '@pezkuwi/types/interfaces';
|
||||
import type { SubmittableResult } from '../index.js';
|
||||
|
||||
// log all events for the transfers, calling done() when finalized
|
||||
export const logEvents = (done: () => Record<string, unknown>): (r: SubmittableResult) => void =>
|
||||
({ events, status }: SubmittableResult): void => {
|
||||
console.log('Transaction status:', status.type);
|
||||
|
||||
if (status.isInBlock) {
|
||||
console.log('Completed at block hash', status.value.toHex());
|
||||
console.log('Events:');
|
||||
|
||||
events.forEach(({ event: { data, method, section }, phase }: EventRecord): void => {
|
||||
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
|
||||
});
|
||||
|
||||
if (events.length) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user