Skip to content

Commit

Permalink
feat(txwrapper): support gearVoucher pallet (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored May 28, 2024
1 parent e22669f commit 8c604f3
Show file tree
Hide file tree
Showing 23 changed files with 755 additions and 448 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules/
**/.DS_Store
.idea
.yarn/*
**/.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
Expand Down
1 change: 0 additions & 1 deletion tools/txwrapper/.gitignore

This file was deleted.

Binary file removed tools/txwrapper/.yarn/install-state.gz
Binary file not shown.
24 changes: 12 additions & 12 deletions tools/txwrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@gear-js/txwrapper",
"version": "0.0.1",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@substrate/txwrapper-core": "^6.0.1"
"@substrate/txwrapper-core": "7.4.0"
},
"bugs": {
"url": "https://github.com/gear-tech/gear-js/issues"
Expand All @@ -22,16 +22,16 @@
"license": "GPL-3.0",
"author": "Gear Technologies",
"devDependencies": {
"@polkadot/api": "^10.7.1",
"@substrate/txwrapper-dev": "6.0.0",
"@types/jest": "^29.5.2",
"@types/node-fetch": "^2.6.4",
"babel-jest": "^29.5.0",
"jest": "^29.5.0",
"node-fetch": "2",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
"@polkadot/api": "11.1.1",
"@substrate/txwrapper-dev": "7.4.0",
"@types/jest": "29.5.12",
"@types/node-fetch": "2.6.11",
"babel-jest": "29.7.0",
"jest": "29.7.0",
"node-fetch": "2.7.0",
"ts-jest": "29.1.3",
"ts-node": "10.9.2",
"typescript": "5.4.5"
},
"scripts": {
"test": "jest",
Expand Down
5 changes: 5 additions & 0 deletions tools/txwrapper/src/methods/gear/createProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export interface CreateProgramArgs extends Args {
* The value to be transferred to the program.
*/
value: string | number;

/**
* A flag that indicates whether the account should be kept alive after the value is sent to the program.
*/
keepAlive: boolean;
}

/**
Expand Down
1 change: 0 additions & 1 deletion tools/txwrapper/src/methods/gear/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './claimValue';
export * from './createProgram';
export * from './payProgramRent';
export * from './sendMessage';
export * from './sendReply';
export * from './uploadCode';
Expand Down
5 changes: 5 additions & 0 deletions tools/txwrapper/src/methods/gear/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface SendMessageArgs extends Args {
* The value to be transferred to the program.
*/
value: string | number;

/**
* A flag that indicates whether the account should be kept alive after the value is sent to the program.
*/
keepAlive: boolean;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tools/txwrapper/src/methods/gear/sendReply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface SendReplyArgs extends Args {
* The value to be transferred to the program.
*/
value: string | number;

/**
* A flag that indicates whether the account should be kept alive after the value is sent to the program.
*/
keepAlive: boolean;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tools/txwrapper/src/methods/gear/uploadProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export interface UploadProgramArgs extends Args {
* The value to be transferred to the program.
*/
value: string | number;

/**
* A flag that indicates whether the account should be kept alive after the value is sent to the program.
*/
keepAlive: boolean;
}

/**
Expand Down
54 changes: 54 additions & 0 deletions tools/txwrapper/src/methods/gearVoucher/call.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Args, BaseTxInfo, defineMethod, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-core';
import { SendMessageArgs } from '../gear/sendMessage';
import { SendReplyArgs } from '../gear/sendReply';
import { UploadCodeArgs } from '../gear/uploadCode';
import { DeclineArgs } from './decline';

export interface SendMessageWithVoucher extends Args {
SendMessage: SendMessageArgs;
}

export interface SendReplyWithVoucher extends Args {
SendReply: SendReplyArgs;
}

export interface UploadCodeWithVoucher extends Args {
UploadCode: UploadCodeArgs;
}

export interface DeclineVoucherWithVoucher extends Args {
DeclineVoucher: DeclineArgs;
}

export interface CallArgs extends Args {
/**
* The id of the voucher to be used.
*/
voucherId: string;

/**
* Call options
*/
call: SendMessageWithVoucher | SendReplyWithVoucher | UploadCodeWithVoucher | DeclineVoucherWithVoucher;
}

/**
* Construct a createProgram transaction offline.
*
* @param args - Arguments specific to this method.
* @param info - Information required to construct the transaction.
* @param options - Registry and metadata used for constructing the method.
*/
export function call(args: CallArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction {
return defineMethod(
{
method: {
args,
name: 'call',
pallet: 'gearVoucher',
},
...info,
},
options,
);
}
29 changes: 29 additions & 0 deletions tools/txwrapper/src/methods/gearVoucher/decline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Args, BaseTxInfo, defineMethod, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-core';

export interface DeclineArgs extends Args {
/**
* The id of the voucher to be declined.
*/
voucherId: string;
}

/**
* Construct a decline voucher transaction offline.
*
* @param args - Arguments specific to this method.
* @param info - Information required to construct the transaction.
* @param options - Registry and metadata used for constructing the method.
*/
export function decline(args: DeclineArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction {
return defineMethod(
{
method: {
args,
name: 'decline',
pallet: 'gearVoucher',
},
...info,
},
options,
);
}
5 changes: 5 additions & 0 deletions tools/txwrapper/src/methods/gearVoucher/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './call';
export * from './decline';
export * from './issue';
export * from './revoke';
export * from './update';
49 changes: 49 additions & 0 deletions tools/txwrapper/src/methods/gearVoucher/issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Args, BaseTxInfo, defineMethod, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-core';

export interface IssueArgs extends Args {
/**
* The voucher holder account id.
*/
spender: string;

/**
* The voucher amount.
*/
value: string | number;

/**
* The number of the block until which the voucher is valid. If not specified, the voucher is valid in `api.voucher.minDuration` blocks.
*/
duration: string | number;

/**
* The list of programs that the voucher can be used for. If not specified, the voucher can be used for any program.
*/
programs: string[] | null;

/**
* Whether the voucher can be used for uploading code.
*/
codeUploading: boolean;
}

/**
* Construct a decline voucher transaction offline.
*
* @param args - Arguments specific to this method.
* @param info - Information required to construct the transaction.
* @param options - Registry and metadata used for constructing the method.
*/
export function issue(args: IssueArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction {
return defineMethod(
{
method: {
args,
name: 'issue',
pallet: 'gearVoucher',
},
...info,
},
options,
);
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
import { Args, BaseTxInfo, defineMethod, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-core';

export interface PayProgramRentArgs extends Args {
export interface RevokeArgs extends Args {
/**
* The program id.
* The voucher holder account id.
*/
programId: string;
spender: string;

/**
* The block count to pay for.
* The id of the voucher to be revoked.
*/
blockCount: number;
voucherId: string;
}

/**
* Construct a payProgramRent transaction offline.
* Construct a decline voucher transaction offline.
*
* @param args - Arguments specific to this method.
* @param info - Information required to construct the transaction.
* @param options - Registry and metadata used for constructing the method.
*/
export function payProgramRent(
args: PayProgramRentArgs,
info: BaseTxInfo,
options: OptionsWithMeta,
): UnsignedTransaction {
export function revoke(args: RevokeArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction {
return defineMethod(
{
method: {
args,
name: 'payProgramRent',
pallet: 'gear',
name: 'revoke',
pallet: 'gearVoucher',
},
...info,
},
Expand Down
59 changes: 59 additions & 0 deletions tools/txwrapper/src/methods/gearVoucher/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Args, BaseTxInfo, defineMethod, OptionsWithMeta, UnsignedTransaction } from '@substrate/txwrapper-core';

export interface UpdateArgs extends Args {
/**
* The voucher holder account id.
*/
spender: string;

/**
* The id of the voucher to be revoked.
*/
voucherId: string;

/**
* The new voucher owner.
*/
moveOwnership: string | null;

/**
* The new voucher balance.
*/
balanceTopUp: number | string | null;

/**
* Append new programs to the voucher.
*/
appendPrograms: string[] | null;

/**
* Enable or disable code uploading.
*/
codeUploading: boolean | null;

/**
* Prolong the duration of th voucher validity.
*/
prolongDuration: number | null;
}

/**
* Construct a decline voucher transaction offline.
*
* @param args - Arguments specific to this method.
* @param info - Information required to construct the transaction.
* @param options - Registry and metadata used for constructing the method.
*/
export function update(args: UpdateArgs, info: BaseTxInfo, options: OptionsWithMeta): UnsignedTransaction {
return defineMethod(
{
method: {
args,
name: 'update',
pallet: 'gearVoucher',
},
...info,
},
options,
);
}
1 change: 1 addition & 0 deletions tools/txwrapper/src/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * as gear from './gear';
export * as gearVoucher from './gearVoucher';
2 changes: 1 addition & 1 deletion tools/txwrapper/test/METADATA_HEX.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tools/txwrapper/test/SPEC_VERSION.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default 160;
export default 1310;
2 changes: 1 addition & 1 deletion tools/txwrapper/test/TEST_BASE_TX_INFO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import METADATA_HEX from './METADATA_HEX';
import SPEC_VERSION from './SPEC_VERSION';

export default {
address: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', // seed "//Alice"
address: 'kGkLEU3e3XXkJp2WK4eNpVmSab5xUNL9QtmLPh8QfCL2EgotW', // seed "//Alice"
blockHash: '0x753a7c960b1ab127334afa81a3a7d4e4af9355d91d35404e4663413055b97b94',
blockNumber: 7621828,
eraPeriod: 2400,
Expand Down
Loading

0 comments on commit 8c604f3

Please sign in to comment.