Skip to content

Commit

Permalink
feat: Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Apr 27, 2021
1 parent 1111853 commit 3c3b897
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@confio/relayer": "^0.1.3",
"@cosmjs/launchpad": "^0.24.1",
"core-js": "^3.6.5",
"long": "^4.0.0",
"vue": "^3.0.0"
},
"devDependencies": {
Expand Down
62 changes: 49 additions & 13 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
<button v-on:click="runRelayer">Run Relayer</button>
</div>
<div v-if="step==5">
<button v-on:click="stopRelayer">Stop Relayer</button>
<button v-on:click="sendIBCtransaction">Send Demo Transaction</button>
<button v-on:click="stopRelayer">Stop Relayer</button><br/>
<input v-model="transaction.senderMnemonic" placeholder="Sender mnemonic on chain A"/><br/>
<input v-model="transaction.rcptAddress" placeholder="Recipient address on chain b"/><br/>
<input v-model="transaction.amount" placeholder="Amount to transfer (e.g. 1token)"/><br/>
<button v-on:click="sendIBCtransaction">Send IBC Transfer Transaction</button>
</div>
</div>
</template>
Expand All @@ -40,29 +43,34 @@
import { stringToPath } from "@cosmjs/crypto";
import { IbcClient, Link } from "@confio/relayer/build";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from '@cosmjs/launchpad'
import { GasPrice,parseCoins } from '@cosmjs/launchpad'
import { SigningStargateClient } from "@cosmjs/stargate"
import Long from 'long'
export default {
name: "App",
data() {
return {
step: 1,
config: {
chainA: {
endpoint: "http://localhost:26657",
addrPrefix: "mars",
gasPrice: "0.0001token",
endpoint: "",
addrPrefix: "",
gasPrice: "",
mnemonic:
"purity ancient awesome mobile sight mechanic planet click funny voice truck jazz kingdom tiny series unveil leader analyst about despair orphan observe over camera",
"",
},
chainB: {
endpoint: "http://localhost:26659",
addrPrefix: "planet",
gasPrice: "0.0001token",
mnemonic:
"output gasp join carbon run dismiss hazard sudden digital wrestle robot grunt grief success quarter pill estate castle episode asthma bachelor woman helmet silly",
endpoint: "",
addrPrefix: "",
gasPrice: "",
mnemonic: "",
},
},
transaction: {
senderMnemonic:'',
amount: '',
rcptAddress: ''
},
signerA:null,
signerB:null,
clientA: null,
Expand Down Expand Up @@ -106,6 +114,34 @@ export default {
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
},
async sendIBCtransaction() {
const signer = await DirectSecp256k1HdWallet.fromMnemonic(
this.transaction.senderMnemonic,
stringToPath("m/44'/118'/0'/0/0"),
this.config.chainA.addrPrefix
);
const client = await SigningStargateClient.connectWithSigner(this.config.chainA.endpoint,signer);
const [fromAccount]= (await signer.getAccounts())
const msg = {
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
value: {
sourcePort: 'transfer',
sourceChannel: this.channels.src.channelId,
sender: fromAccount.address,
receiver: this.transaction.rcptAddress,
timeoutTimestamp: Long.fromString(new Date().getTime() + 60000 + '000000'),
token: parseCoins(this.transaction.amount)[0]
},
};
const fee = {
amount: [],
gas: "200000",
};
await client.signAndBroadcast(fromAccount.address, [msg], fee)
},
async relayerLoop(options={ poll: 5000, maxAgeDest: 86400, maxAgeSrc: 86400 }) {
while (this.running) {
try {
Expand Down

0 comments on commit 3c3b897

Please sign in to comment.