Skip to content

Commit

Permalink
successfully implement author_submitAndWatchExtrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Oct 25, 2024
1 parent 6215133 commit af73e1d
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions packages/worker-api/src/websocketWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,41 +155,38 @@ export class Worker {

return new Promise( async (resolve, reject) => {
const onStatusChange = (error: Error | null, result: string) => {
resolve({hash: "mz hash"})
console.log(`DirectRequestStatus: error ${JSON.stringify(error)}`)
console.log(`DirectRequestStatus: ${JSON.stringify(result)}`)

const value = hexToU8a(result);
const returnValue = this.createType('RpcReturnValue', value);
const directRequestStatus = this.createType('DirectRequestStatus', value);

if (returnValue.isError) {
const errorMsg = this.createType('String', returnValue.value);
if (directRequestStatus.isError) {
const errorMsg = this.createType('String', directRequestStatus.value);
throw new Error(`DirectRequestStatus is Error ${errorMsg}`);
}
if (returnValue.isOk) {
const hash = this.createType('Hash', returnValue.value);
resolve({hash: hash})
if (directRequestStatus.isOk) {
// const hash = this.createType('Hash', directRequestStatus.value);
resolve({})
}

if (returnValue.isTrustedOperationStatus) {
const status = returnValue.asTrustedOperationStatus;
const hash = this.createType('Hash', returnValue.value);
if (directRequestStatus.isTrustedOperationStatus) {
console.log(`TrustedOperationStatus: ${directRequestStatus}`)
const status = directRequestStatus.asTrustedOperationStatus;
if (connection_can_be_closed(status)) {
resolve({hash: hash})
resolve({})
}
}

throw( new Error(`Hello: ${JSON.stringify(returnValue)}`));
}

try {
const res = await this.#ws.subscribe('Hash',
const res = await this.#ws.subscribe(method,
method, params, onStatusChange
);
let returnValue = this.resultToRpcReturnValue(res as string);
console.debug(`Subscription RpcReturnValue ${JSON.stringify(returnValue)}`);
let topHash = this.createType('Hash', returnValue.value)
console.debug(`topHash: ${topHash}`);
// let returnValue = this.resultToRpcReturnValue(res as string);
// console.debug(`Subscription RpcReturnValue ${JSON.stringify(returnValue)}`);
let topHash = this.createType('Hash', res);
console.debug(`resHash: ${topHash}`);
} catch (err) {
console.error(err);
reject(err);
Expand Down

0 comments on commit af73e1d

Please sign in to comment.