Skip to content

Commit

Permalink
Remove unused argsEncodeWithABI
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Jun 27, 2024
1 parent 62864c8 commit 89e45e1
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 203 deletions.
42 changes: 1 addition & 41 deletions src/client/lcd/api/MoveAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BaseAPI } from './BaseAPI';
import { AccAddress, Denom, MoveParams, ModuleABI } from '../../../core';
import { AccAddress, Denom, MoveParams } from '../../../core';
import { APIParams, Pagination, PaginationOptions } from '../APIRequester';
import { argsEncodeWithABI } from '../../../util';
import { UpgradePolicy } from '@initia/initia.proto/initia/move/v1/types';

export interface Module {
Expand Down Expand Up @@ -113,45 +112,6 @@ export class MoveAPI extends BaseAPI {
.then(res => JSON.parse(res.data) as T);
}

/**
* Query view function with not encoded arguments and abi.
* Arguments will be bcs encoded with type informations from abi.
*
* @param address
* @param moduleName
* @param functionName
* @param typeArgs
* @param args // not encoded arguments
* @param abi // base64 encoded module abi
* @returns
*/
public async viewFunctionWithABI<T>(
abi: string,
address: AccAddress,
moduleName: string,
functionName: string,
typeArgs: string[] = [],
args: any[] = []
): Promise<T> {
const module: ModuleABI = JSON.parse(Buffer.from(abi, 'base64').toString());

const functionAbi = module.exposed_functions.find(
exposedFunction => exposedFunction.name === functionName
);

if (!functionAbi) {
throw new Error('function not found');
}

return this.viewFunction<T>(
address,
moduleName,
functionName,
typeArgs,
argsEncodeWithABI(args, functionAbi)
);
}

public async view(
address: AccAddress,
moduleName: string,
Expand Down
1 change: 0 additions & 1 deletion src/core/move/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './msgs';
export * from './MoveParams';
export * from './types';
73 changes: 0 additions & 73 deletions src/core/move/msgs/MsgExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { JSONSerializable } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { Any } from '@initia/initia.proto/google/protobuf/any';
import { MsgExecute as MsgExecute_pb } from '@initia/initia.proto/initia/move/v1/tx';
import { argsEncodeWithABI } from '../../../util';
import { ModuleABI } from '../types';

export class MsgExecute extends JSONSerializable<
MsgExecute.Amino,
Expand Down Expand Up @@ -157,77 +155,6 @@ export class MsgExecute extends JSONSerializable<
args,
};
}

/**
* Generate `MsgExecute` from plain arguments(not bcs encoded).
*
* @example
* // In case of the types of arguments are ['u64', 'u64']
* const abi = await lcd.move.module('init1def...', 'pair').then(res => res.abi)
*
* // msg that was generated with not encoded arguments
* consg msg1 = MsgExectueEntryFunction.fromPlainArgs(
* 'init1abc...', // sender
* 'init1def...', // module owner
* 'pair', // moudle name
* 'provide_liquidity', // function name
* [],
* [1000000000000, 2000000000000],
* abi
* );
*
* // msg that was generated with the constructor
* const msg2 = new MsgExecute(
* 'init1abc...', // sender
* 'init1def...', // module owner
* 'pair', // moudle name
* 'provide_liquidity', // function name
* [],
* [
* bcs.serialize('u64', 1000000000000),
* bcs.serialize('u64', 2000000000000),
* ]
* );
*
* console.assert(msg1.toJSON(), msg2.toJSON()
*
* @param sender
* @param module_address
* @param module_name
* @param function_name
* @param type_args
* @param args
* @param abi // base64 encoded module abi
* @returns
*/
public static fromPlainArgs(
sender: AccAddress,
module_address: AccAddress,
module_name: string,
function_name: string,
type_args: string[] = [],
args: any[] = [],
abi: string
): MsgExecute {
const module: ModuleABI = JSON.parse(abi);

const functionAbi = module.exposed_functions.find(
exposedFunction => exposedFunction.name === function_name
);

if (!functionAbi) {
throw new Error('function not found');
}

return new MsgExecute(
sender,
module_address,
module_name,
function_name,
type_args,
argsEncodeWithABI(args, functionAbi)
);
}
}

export namespace MsgExecute {
Expand Down
55 changes: 0 additions & 55 deletions src/core/move/msgs/MsgScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { JSONSerializable } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { Any } from '@initia/initia.proto/google/protobuf/any';
import { MsgScript as MsgScript_pb } from '@initia/initia.proto/initia/move/v1/tx';
import { MoveFunctionABI } from '../types';
import { argsEncodeWithABI } from '../../../util';

export class MsgScript extends JSONSerializable<
MsgScript.Amino,
Expand Down Expand Up @@ -96,59 +94,6 @@ export class MsgScript extends JSONSerializable<
args,
};
}

/**
* Generate `MsgScript` from plain arguments(not bcs encoded)
*
* @example
* // In case of the types of arguments are ['u64', 'u64']
* const abi = await lcd.move.scriptABI(script).then(res => res.abi)
*
* // msg that was generated with not encoded arguments
* consg msg1 = MsgScript.fromPlainArgs(
* 'init1abc...', // sender
* script, // code bytes
* [],
* [1000000000000, 2000000000000],
* abi
* );
*
* // msg that was generated with the constructor
* const msg2 = new MsgScript(
* 'init1abc...', // sender
* script, // code bytes
* [],
* [
* bcs.serialize('u64', 1000000000000),
* bcs.serialize('u64', 2000000000000),
* ]
* );
*
* console.assert(msg1.toJSON(), msg2.toJSON()
*
* @param sender
* @param code_bytes
* @param type_args
* @param args
* @param abi // base64 encoded script abi
* @returns
*/
public static fromPlainArgs(
sender: AccAddress,
code_bytes: string,
type_args: string[],
args: any[],
abi: string
): MsgScript {
const functionAbi: MoveFunctionABI = JSON.parse(abi);

return new MsgScript(
sender,
code_bytes,
type_args,
argsEncodeWithABI(args, functionAbi)
);
}
}

export namespace MsgScript {
Expand Down
32 changes: 0 additions & 32 deletions src/core/move/types.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './bcsLegacy';
export * from './bcs';
export * from './hash';
export * from './json';

0 comments on commit 89e45e1

Please sign in to comment.