-
Notifications
You must be signed in to change notification settings - Fork 1
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
Youngjoon Lee
committed
Jun 16, 2021
1 parent
7f4f4f6
commit 638cf37
Showing
5 changed files
with
138 additions
and
2 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
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,19 @@ | ||
#!/bin/bash | ||
|
||
#set -eo pipefail | ||
set -euxo pipefail | ||
|
||
SRC_PATH="third_party/proto" | ||
DST_PATH="src/proto" | ||
|
||
# Fetch 3rd-party proto files | ||
protodep up -u | ||
|
||
# Compile only Panacea proto files | ||
mkdir -p ${DST_PATH} | ||
protoc \ | ||
--plugin=./node_modules/.bin/protoc-gen-ts_proto \ | ||
--ts_proto_out="${DST_PATH}" \ | ||
--proto_path="${SRC_PATH}" \ | ||
--ts_proto_opt="esModuleInterop=true,forceLong=long,useOptional=true" \ | ||
${SRC_PATH}/panacea/**/*.proto |
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,112 @@ | ||
import { stringToPath } from "@cosmjs/crypto"; | ||
import { DirectSecp256k1HdWallet, GeneratedType, Registry } from "@cosmjs/proto-signing"; | ||
import { | ||
assertIsBroadcastTxSuccess, | ||
createProtobufRpcClient, | ||
defaultRegistryTypes, | ||
QueryClient, | ||
SigningStargateClient | ||
} from '@cosmjs/stargate'; | ||
import { MsgCreateTopic } from '../src/pb/aol/tx'; | ||
import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; | ||
import { QueryClientImpl } from '../src/pb/aol/query'; | ||
|
||
const rpcEndpoint = "http://localhost:26657" | ||
const mnemonic = "bless front exercise burst solid venture vapor asthma clean table recall affair decrease hollow fabric voice display grid slim bag kingdom hole junior polar"; | ||
const walletOpts = { | ||
hdPaths: [stringToPath("m/44'/371'/0'/0/0")], | ||
prefix: "panacea", | ||
} | ||
|
||
describe('yo', () => { | ||
it('it1', async () => { | ||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, walletOpts); | ||
const [firstAccount] = await wallet.getAccounts(); | ||
|
||
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet); | ||
|
||
const msg = { | ||
typeUrl: "/cosmos.bank.v1beta1.MsgSend", | ||
value: { | ||
fromAddress: firstAccount.address, | ||
toAddress: "panacea1trm407dm66g6mccm4k080e3mh3frcqqy743a74", | ||
amount: [{ | ||
denom: "umed", | ||
amount: "100", | ||
}], | ||
}, | ||
}; | ||
|
||
const fees = { | ||
amount: [ | ||
{ | ||
denom: "umed", | ||
amount: "1000000", | ||
}, | ||
], | ||
gas: "100000", | ||
}; | ||
|
||
const result = await client.signAndBroadcast(firstAccount.address, [msg], fees, "this is a memo"); | ||
assertIsBroadcastTxSuccess(result); | ||
|
||
const coins = await client.getAllBalances(firstAccount.address); | ||
console.log(coins); | ||
}); | ||
|
||
it('custom module', async () => { | ||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, walletOpts); | ||
const [firstAccount] = await wallet.getAccounts(); | ||
|
||
const a: [string, GeneratedType] = ["/medibloc.panaceacore.aol.MsgCreateTopic", MsgCreateTopic]; | ||
const i: Iterable<[string, GeneratedType]> = [...defaultRegistryTypes, a]; | ||
const myRegistry = new Registry(i); | ||
|
||
|
||
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet, { registry: myRegistry }); | ||
|
||
const msg = { | ||
typeUrl: "/medibloc.panaceacore.aol.MsgCreateTopic", | ||
value: { | ||
topicName: "topic1", | ||
description: "this is a description", | ||
ownerAddress: firstAccount.address, | ||
}, | ||
}; | ||
|
||
const fees = { | ||
amount: [ | ||
{ | ||
denom: "umed", | ||
amount: "1000000", | ||
}, | ||
], | ||
gas: "100000", | ||
}; | ||
|
||
const result = await client.signAndBroadcast(firstAccount.address, [msg], fees, "this is a memo"); | ||
assertIsBroadcastTxSuccess(result); | ||
}); | ||
|
||
it('custom module - query', async () => { | ||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, walletOpts); | ||
const [firstAccount] = await wallet.getAccounts(); | ||
|
||
// Tendermint34Client knows how to talk to the Tendermint RPC endpoint | ||
const tmClient = await Tendermint34Client.connect(rpcEndpoint); | ||
// The generic Stargate query client knows how to use the Tendermint34Client to submit unverified ABCI queries | ||
const queryClient = new QueryClient(tmClient); | ||
// This helper function wraps the generic Stargate query client for use by the specific generated query client. | ||
const rpcClient = createProtobufRpcClient(queryClient); | ||
|
||
// Here we instantiate a specific query client which will have the custom methods defined in the proto file. | ||
const queryService = new QueryClientImpl(rpcClient); | ||
|
||
const result = await queryService.Topic({ | ||
ownerAddress: firstAccount.address, | ||
topicName: "topic1", | ||
}); | ||
|
||
console.log(result); | ||
}); | ||
}); |
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