Skip to content

Commit

Permalink
use fn name instead of index for encoding payload
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Dec 11, 2023
1 parent 7a1743d commit 3b6c04a
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions js/src/generate/service-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export class ServiceGenerator {
private generateMethods(methods: IServiceMethod[]) {
this._out.import('@polkadot/types/types', 'IKeyringPair');

let messageIndex = 0;
let queryIndex = 0;
for (const {
def: { args, name, output },
kind,
Expand All @@ -57,22 +55,20 @@ export class ServiceGenerator {
kind,
)}): Promise<${returnType}>`,
() => {
let index = kind === 'message' ? messageIndex : queryIndex;
if (args.length === 0) {
this._out.line(`const payload = this.registry.createType('u8', ${index}).toU8a()`);
this._out.line(`const payload = this.registry.createType('String', '${name}/').toU8a()`);
} else {
this._out
.line(`const payload = [`, false)
.increaseIndent()
.line(`...this.registry.createType('u8', ${index}).toU8a(),`, false);
.line(`...this.registry.createType('String', '${name}/').toU8a(),`, false);
for (const { name, type } of args) {
this._out.line(`...this.registry.createType('${getType(type, true)}', ${name}).toU8a(),`, false);
}
this._out.reduceIndent().line(']');
}

if (kind === 'message') {
messageIndex++;
this._out
.line(`const replyPayloadBytes = await this.submitMsgAndWaitForReply(`, false)
.increaseIndent()
Expand All @@ -84,7 +80,6 @@ export class ServiceGenerator {
.line(`const result = this.registry.createType('${getType(output, true)}', replyPayloadBytes)`)
.line(`return result.toJSON() as ${returnType}`);
} else if (kind === 'query') {
queryIndex++;
this._out
.line(`const stateBytes = await this.api.programState.read({ programId: this.programId, payload})`)
.line(`const result = this.registry.createType('${getType(output, true)}', stateBytes)`)
Expand Down

0 comments on commit 3b6c04a

Please sign in to comment.