Skip to content

Commit

Permalink
Add bindings for SampleGoContract (#301)
Browse files Browse the repository at this point in the history
This contract is only used for testing.
  • Loading branch information
Sriep authored and enlight committed Aug 27, 2019
1 parent df321da commit f2eec86
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/gen-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const protoFiles = [
'dpos.proto',
'dposv2.proto',
'dposv3.proto',
'sample_go_contract.proto',
'user_deployer_whitelist.proto'
]

Expand Down
1 change: 1 addition & 0 deletions src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { LoomCoinTransferGateway } from './loomcoin-gateway'
export { TronTransferGateway } from './tron-gateway'
export { BinanceTransferGateway } from './binance-gateway'
export { UserDeployerWhitelist } from './user-deployer-whitelist'
export { SampleGoContract } from './sample-go-contract'
34 changes: 34 additions & 0 deletions src/contracts/sample-go-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import BN from 'bn.js'
import { Client } from '../client'
import { Contract } from '../contract'
import { Address } from '../address'
import { SampleGoContractNestedEvmRequest } from '../proto/sample_go_contract_pb'

export class SampleGoContract extends Contract {
static async createAsync(client: Client, callerAddr: Address): Promise<SampleGoContract> {
const contractAddr = await client.getContractAddressAsync('sample-go-contract')
if (!contractAddr) {
throw Error('Failed to resolve contract address')
}
return new SampleGoContract({ contractAddr, callerAddr, client })
}

constructor(params: { contractAddr: Address; callerAddr: Address; client: Client }) {
super(params)
}

testNestedEvmCallsAsync(
innerEmitter: Address,
outerEmitter: Address,
innerEmitterValue: number,
outerEmitterValue: number
): Promise<Uint8Array | void> {
const request = new SampleGoContractNestedEvmRequest()
request.setInnerEmitter(innerEmitter.MarshalPB())
request.setOuterEmitter(outerEmitter.MarshalPB())
request.setInnerEmitterValue(innerEmitterValue)
request.setOuterEmitterValue(outerEmitterValue)

return this.callAsync<void>('TestNestedEvmCalls', request)
}
}
11 changes: 11 additions & 0 deletions src/proto/sample_go_contract.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

import "proto/loom.proto";

message SampleGoContractNestedEvmRequest {
Address inner_emitter = 1;
Address outer_emitter = 2;
uint64 inner_emitter_value = 3;
uint64 outer_emitter_value = 4;
}

42 changes: 42 additions & 0 deletions src/proto/sample_go_contract_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// package:
// file: proto/sample_go_contract.proto

import * as jspb from "google-protobuf";
import * as proto_loom_pb from "../proto/loom_pb";

export class SampleGoContractNestedEvmRequest extends jspb.Message {
hasInnerEmitter(): boolean;
clearInnerEmitter(): void;
getInnerEmitter(): proto_loom_pb.Address | undefined;
setInnerEmitter(value?: proto_loom_pb.Address): void;

hasOuterEmitter(): boolean;
clearOuterEmitter(): void;
getOuterEmitter(): proto_loom_pb.Address | undefined;
setOuterEmitter(value?: proto_loom_pb.Address): void;

getInnerEmitterValue(): number;
setInnerEmitterValue(value: number): void;

getOuterEmitterValue(): number;
setOuterEmitterValue(value: number): void;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SampleGoContractNestedEvmRequest.AsObject;
static toObject(includeInstance: boolean, msg: SampleGoContractNestedEvmRequest): SampleGoContractNestedEvmRequest.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: SampleGoContractNestedEvmRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): SampleGoContractNestedEvmRequest;
static deserializeBinaryFromReader(message: SampleGoContractNestedEvmRequest, reader: jspb.BinaryReader): SampleGoContractNestedEvmRequest;
}

export namespace SampleGoContractNestedEvmRequest {
export type AsObject = {
innerEmitter?: proto_loom_pb.Address.AsObject,
outerEmitter?: proto_loom_pb.Address.AsObject,
innerEmitterValue: number,
outerEmitterValue: number,
}
}

0 comments on commit f2eec86

Please sign in to comment.