-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { AccAddress, EvmParams } from '../../../core'; | ||
import { APIParams } from '../APIRequester'; | ||
import { BaseAPI } from './BaseAPI'; | ||
|
||
export interface CallResponse { | ||
response: string; | ||
used_gas: string; | ||
logs: { | ||
address: AccAddress; | ||
topics: string[]; | ||
data: string; | ||
}[]; | ||
trace_output: string; | ||
} | ||
|
||
export class EvmAPI extends BaseAPI { | ||
public async code( | ||
contractAddr: AccAddress, | ||
params: APIParams = {} | ||
): Promise<string> { | ||
return this.c | ||
.get<{ code: string }>(`/minievm/evm/v1/codes/${contractAddr}`, params) | ||
.then(d => d.code); | ||
} | ||
|
||
public async state( | ||
contractAddr: AccAddress, | ||
key: string, | ||
params: APIParams = {} | ||
): Promise<string> { | ||
return this.c | ||
.get<{ value: string }>( | ||
`/minievm/evm/v1/states/${contractAddr}/${key}`, | ||
params | ||
) | ||
.then(d => d.value); | ||
} | ||
|
||
public async contractAddrByDenom( | ||
denom: string, | ||
params: APIParams = {} | ||
): Promise<AccAddress> { | ||
return this.c | ||
.get<{ address: AccAddress }>(`/minievm/evm/v1/contracts/by_denom`, { | ||
...params, | ||
denom, | ||
}) | ||
.then(d => d.address); | ||
} | ||
|
||
public async denom( | ||
contractAddr: AccAddress, | ||
params: APIParams = {} | ||
): Promise<string> { | ||
return this.c | ||
.get<{ denom: string }>(`/minievm/evm/v1/denoms/${contractAddr}`, params) | ||
.then(d => d.denom); | ||
} | ||
|
||
public async call( | ||
sender: AccAddress, | ||
contractAddr: AccAddress, | ||
input: string, | ||
withTrace: boolean | ||
): Promise<CallResponse> { | ||
return this.c.post<CallResponse>(`/minievm/evm/v1/call`, { | ||
sender, | ||
contract_addr: contractAddr, | ||
input, | ||
with_trace: withTrace, | ||
}); | ||
} | ||
|
||
public async parameters(params: APIParams = {}): Promise<EvmParams> { | ||
return this.c | ||
.get<{ params: EvmParams.Data }>(`/minievm/evm/v1/params`, params) | ||
.then(({ params: d }) => EvmParams.fromData(d)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { JSONSerializable } from '../../util/json'; | ||
import { Params as Params_pb } from '@initia/initia.proto/minievm/evm/v1/types'; | ||
|
||
export class EvmParams extends JSONSerializable< | ||
EvmParams.Amino, | ||
EvmParams.Data, | ||
EvmParams.Proto | ||
> { | ||
/** | ||
* @param extra_eips the additional EIPs for the vm.Config | ||
* @param allowed_publishers list of addresses with permission to distribute contracts | ||
*/ | ||
constructor( | ||
public extra_eips: number[], | ||
public allowed_publishers: string[] | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromAmino(data: EvmParams.Amino): EvmParams { | ||
const { extra_eips, allowed_publishers } = data; | ||
return new EvmParams(extra_eips.map(Number.parseInt), allowed_publishers); | ||
} | ||
|
||
public toAmino(): EvmParams.Amino { | ||
const { extra_eips, allowed_publishers } = this; | ||
return { | ||
extra_eips: extra_eips.map(eip => eip.toString()), | ||
allowed_publishers, | ||
}; | ||
} | ||
|
||
public static fromData(data: EvmParams.Data): EvmParams { | ||
const { extra_eips, allowed_publishers } = data; | ||
return new EvmParams(extra_eips.map(Number.parseInt), allowed_publishers); | ||
} | ||
|
||
public toData(): EvmParams.Data { | ||
const { extra_eips, allowed_publishers } = this; | ||
return { | ||
extra_eips: extra_eips.map(eip => eip.toString()), | ||
allowed_publishers, | ||
}; | ||
} | ||
|
||
public static fromProto(proto: EvmParams.Proto): EvmParams { | ||
return new EvmParams( | ||
proto.extraEips.map(eip => eip.toNumber()), | ||
proto.allowedPublishers | ||
); | ||
} | ||
|
||
public toProto(): EvmParams.Proto { | ||
const { extra_eips, allowed_publishers } = this; | ||
return Params_pb.fromPartial({ | ||
extraEips: extra_eips, | ||
allowedPublishers: allowed_publishers, | ||
}); | ||
} | ||
} | ||
|
||
export namespace EvmParams { | ||
export interface Amino { | ||
extra_eips: string[]; | ||
allowed_publishers: string[]; | ||
} | ||
|
||
export interface Data { | ||
extra_eips: string[]; | ||
allowed_publishers: string[]; | ||
} | ||
|
||
export type Proto = Params_pb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './msgs'; | ||
export * from './EvmParams'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { JSONSerializable } from '../../../util/json'; | ||
import { AccAddress } from '../../bech32'; | ||
import { Any } from '@initia/initia.proto/google/protobuf/any'; | ||
import { MsgCall as MsgCall_pb } from '@initia/initia.proto/minievm/evm/v1/tx'; | ||
|
||
export class MsgCall extends JSONSerializable< | ||
MsgCall.Amino, | ||
MsgCall.Data, | ||
MsgCall.Proto | ||
> { | ||
/** | ||
* @param sender the actor that signed the messages | ||
* @param contract_addr the contract address to be executed, can be cosmos address or hex encoded address | ||
* @param input hex encoded execution input bytes | ||
*/ | ||
constructor( | ||
public sender: AccAddress, | ||
public contract_addr: AccAddress, | ||
public input: string | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromAmino(data: MsgCall.Amino): MsgCall { | ||
const { | ||
value: { sender, contract_addr, input }, | ||
} = data; | ||
|
||
return new MsgCall(sender, contract_addr, input); | ||
} | ||
|
||
public toAmino(): MsgCall.Amino { | ||
const { sender, contract_addr, input } = this; | ||
return { | ||
type: 'evm/MsgCall', | ||
value: { | ||
sender, | ||
contract_addr, | ||
input, | ||
}, | ||
}; | ||
} | ||
|
||
public static fromData(data: MsgCall.Data): MsgCall { | ||
const { sender, contract_addr, input } = data; | ||
return new MsgCall(sender, contract_addr, input); | ||
} | ||
|
||
public toData(): MsgCall.Data { | ||
const { sender, contract_addr, input } = this; | ||
return { | ||
'@type': '/minievm.evm.v1.MsgCall', | ||
sender, | ||
contract_addr, | ||
input, | ||
}; | ||
} | ||
|
||
public static fromProto(data: MsgCall.Proto): MsgCall { | ||
return new MsgCall(data.sender, data.contractAddr, data.input); | ||
} | ||
|
||
public toProto(): MsgCall.Proto { | ||
const { sender, contract_addr, input } = this; | ||
return MsgCall_pb.fromPartial({ | ||
sender, | ||
contractAddr: contract_addr, | ||
input, | ||
}); | ||
} | ||
|
||
public packAny(): Any { | ||
return Any.fromPartial({ | ||
typeUrl: '/minievm.evm.v1.MsgCall', | ||
value: MsgCall_pb.encode(this.toProto()).finish(), | ||
}); | ||
} | ||
|
||
public static unpackAny(msgAny: Any): MsgCall { | ||
return MsgCall.fromProto(MsgCall_pb.decode(msgAny.value)); | ||
} | ||
} | ||
|
||
export namespace MsgCall { | ||
export interface Amino { | ||
type: 'evm/MsgCall'; | ||
value: { | ||
sender: AccAddress; | ||
contract_addr: AccAddress; | ||
input: string; | ||
}; | ||
} | ||
|
||
export interface Data { | ||
'@type': '/minievm.evm.v1.MsgCall'; | ||
sender: AccAddress; | ||
contract_addr: AccAddress; | ||
input: string; | ||
} | ||
|
||
export type Proto = MsgCall_pb; | ||
} |
Oops, something went wrong.