Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Upgraded ledger transactions to stargate format #544

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [UNRELEASED]
* [#529] Upgraded ledger transactions to stargate format
* [#523] Implemented readable messages for IBC messages

## [v0.41.x-14.2]
Expand Down
3 changes: 2 additions & 1 deletion client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ CURRENTUSERADDR = 'ledgerUserAddress';
CURRENTUSERPUBKEY = 'ledgerUserPubKey';
BLELEDGERCONNECTION = 'ledgerBLEConnection'
ADDRESSINDEX = 'addressIndex'

RPC = Meteor.settings.public.remote.rpc;
API = Meteor.settings.public.remote.api;

// import { onPageLoad } from 'meteor/server-render';

Expand Down
8 changes: 4 additions & 4 deletions default_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
"gov": true,
"distribution": false
},
"remote": {
"rpc": "https://rpc.stargate.forbole.com:443",
"api": "https://api.stargate.forbole.com:443"
},
"coingeckoId": "cosmos",
"networks": "https://gist.githubusercontent.com/kwunyeung/8be4598c77c61e497dfc7220a678b3ee/raw/bd-networks.json",
"banners": false
},
"remote":{
"rpc":"https://rpc.stargate.forbole.com:443",
"api":"https://api.stargate.forbole.com:443"
},
"debug": {
"startTimer": true
},
Expand Down
19 changes: 0 additions & 19 deletions imports/api/ledger/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@ import { HTTP } from 'meteor/http';
import { Validators } from '../../validators/validators';

Meteor.methods({
'transaction.submit': function(txInfo) {
this.unblock();
const url = `${API}/txs`;
data = {
"tx": txInfo.value,
"mode": "sync"
}
const timestamp = new Date().getTime();
console.log(`submitting transaction${timestamp} ${url} with data ${JSON.stringify(data)}`)

let response = HTTP.post(url, {data});
console.log(`response for transaction${timestamp} ${url}: ${JSON.stringify(response)}`)
if (response.statusCode == 200) {
let data = response.data
if (data.code)
throw new Meteor.Error(data.code, JSON.parse(data.raw_log).message)
return response.data.txhash;
}
},
'transaction.execute': function(body, path) {
this.unblock();
const url = `${API}/${path}`;
Expand Down
60 changes: 31 additions & 29 deletions imports/ui/ledger/LedgerActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class LedgerButton extends Component {
if (res){
let gasPrice = calculateGasPrice(res)
let amountToTransfer = this.state.transferAmount?.amount || this.state.delegateAmount?.amount || this.state.depositAmount?.amount
let totalAmount = this.props.rewards || this.props.commission || this.state.actionType === 'redelegate' || this.state.actionType === 'undelegate'? gasPrice : amountToTransfer + gasPrice;
let totalAmount = this.props.rewards || this.props.commission || this.state.actionType === 'redelegate' || this.state.actionType === 'undelegate' || this.state.actionType === 'vote'? gasPrice : amountToTransfer + gasPrice;
if (totalAmount <= this.state.currentUser?.availableCoin?._amount){
Ledger.applyGas(txMsg, res, Meteor.settings.public.ledger.gasPrice, Coin.StakingCoin.denom);
this.setStateOnSuccess('simulating', {
Expand All @@ -452,23 +452,25 @@ class LedgerButton extends Component {
let txMsg = this.state.txMsg;
const txContext = this.getTxContext();
const bytesToSign = Ledger.getBytesToSign(txMsg, txContext);
this.ledger.sign(bytesToSign, this.state.transportBLE).then((sig) => {
try {
Ledger.applySignature(txMsg, txContext, sig);
Meteor.call('transaction.submit', txMsg, (err, res) => {
if (err) {
this.setStateOnError('signing', err.reason)
} else if (res) {
this.setStateOnSuccess('signing', {
txHash: res,
activeTab: '4'
})
}

if (txMsg.value.msg[0].type === "cosmos-sdk/MsgVote" ||
txMsg.value.msg[0].type === "cosmos-sdk/MsgDeposit" ||
txMsg.value.msg[0].type === "cosmos-sdk/MsgSubmitProposal") {
this.ledger.signAmino(txMsg, txContext, this.state.transportBLE).then((res) => {
this.setStateOnSuccess('signing', {
txHash: res,
activeTab: '4'
})
} catch (e) {
this.setStateOnError('signing', e.message)
}
}, (err) => this.setStateOnError('signing', err.message))
}, (err) => this.setStateOnError('signing', err.message))
}
else {
this.ledger.signTx(txMsg, txContext, this.state.transportBLE).then((hash) => {
this.setStateOnSuccess('signing', {
txHash: hash,
activeTab: '4'
})
}, (err) => this.setStateOnError('signing', err.message))
}
} catch (e) {
this.setStateOnError('signing', e.message)
}
Expand Down Expand Up @@ -769,10 +771,10 @@ class DelegationButtons extends LedgerButton {
class WithdrawButton extends LedgerButton {

createMessage = (callback) => {
Meteor.call('transaction.execute', {from: this.state.user}, this.getPath(), (err, res) =>{
if (res){
Meteor.call('transaction.execute', { from: this.state.user }, this.getPath(), (err, res) => {
if (res) {
Meteor.call('isValidator', this.state.user, (error, result) => {
if (result && result.operator_address){
if (result && result.operator_address) {
res.value.msg.push({
type: 'cosmos-sdk/MsgWithdrawValidatorCommission',
value: { validator_address: result.operator_address }
Expand Down Expand Up @@ -960,18 +962,17 @@ class ProposalActionButtons extends LedgerButton {
renderActionTab = () => {
if (!this.state.currentUser) return null;
let maxAmount = this.state.currentUser.availableCoin;

let inputs;
let title;
switch (this.state.actionType) {
case Types.VOTE:
title=`Vote on Proposal ${this.props.proposalId}`
inputs = (<Input type="select" name="voteOption" onChange={this.handleInputChange} defaultValue=''>
<option value='' disabled>Vote Option</option>
<option value='Yes'>yes</option>
<option value='Abstain'>abstain</option>
<option value='No'>no</option>
<option value='NoWithVeto'>no with veto</option>
<option value='VOTE_OPTION_YES'>yes</option>
<option value='VOTE_OPTION_ABSTAIN'>abstain</option>
<option value='VOTE_OPTION_NO'>no</option>
<option value='VOTE_OPTION_NO_WITH_VETO'>no with veto</option>
</Input>)
break;
case Types.DEPOSIT:
Expand All @@ -982,15 +983,16 @@ class ProposalActionButtons extends LedgerButton {
min={Coin.MinStake} max={maxAmount.stakingAmount} type="number"
invalid={this.state.depositAmount != null && !isBetween(this.state.depositAmount, 1, maxAmount)}/>
<InputGroupAddon addonType="append">{Coin.StakingCoin.displayName}</InputGroupAddon>
<div>your available balance: <Amount coin={maxAmount}/></div>
</InputGroup>)
</InputGroup>
)
break;
}
return <TabPane tabId="2">
<h3>{title}</h3>
{inputs}
<Input name="memo" onChange={this.handleInputChange}
placeholder="Memo(optional)" type="textarea" value={this.state.memo}/>
{this.state.actionType === 'deposit' ? <div className="mt-2">your available balance: <Amount coin={maxAmount} /></div> : null}
</TabPane>

}
Expand Down Expand Up @@ -1018,7 +1020,7 @@ class ProposalActionButtons extends LedgerButton {
isDataValid = () => {
if (!this.state.currentUser) return false
if (this.state.actionType === Types.VOTE) {
return ['Yes', 'No', 'NoWithVeto', 'Abstain'].indexOf(this.state.voteOption) !== -1;
return ['VOTE_OPTION_YES', 'VOTE_OPTION_NO', 'VOTE_OPTION_NO_WITH_VETO', 'VOTE_OPTION_ABSTAIN'].indexOf(this.state.voteOption) !== -1;
} else {
return isBetween(this.state.depositAmount, 1, this.state.currentUser.availableCoin)
}
Expand All @@ -1027,7 +1029,7 @@ class ProposalActionButtons extends LedgerButton {
getConfirmationMessage = () => {
switch (this.state.actionType) {
case Types.VOTE:
return <span>You are <span className='action'>voting</span> <strong>{this.state.voteOption}</strong> on proposal {this.props.proposalId}
return <span>You are <span className='action'>voting</span> <strong>{this.state.voteOption?.substring(12).replace(/_/g, " ")}</strong> on proposal {this.props.proposalId}
<span> with <Fee gas={this.state.gasEstimate}/>.</span>
</span>
break;
Expand Down
Loading