Skip to content

Commit

Permalink
Fabo/allow signing for terra + emoney (#267)
Browse files Browse the repository at this point in the history
* allow signing for terra

* readd coin conversion

* enable actions for terra

* fix correct terra testnet url

* comments and guards

* enabled more txs for emoney and fixed broadcasting

* added a catch for wrongly formatted broadcast urls
  • Loading branch information
faboweb authored and Bitcoinera committed Jan 20, 2020
1 parent b84cb5c commit 2511cc9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
40 changes: 20 additions & 20 deletions data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"api_url": "https://cosmos-hub-3.lunie.io",
"bech32_prefix": "cosmos",
"source_class_name": "source/cosmosV2-source",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"testnet": false,
"feature_session": true,
"feature_explore": true,
Expand Down Expand Up @@ -65,7 +65,7 @@
"api_url": "https://regen-congo-1.lunie.io",
"bech32_prefix": "xrn:",
"source_class_name": "source/regenV0-source",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"testnet": true,
"feature_session": true,
"feature_explore": true,
Expand All @@ -90,11 +90,11 @@
"id": "terra-testnet",
"title": "Terra",
"chain_id": "soju-0013",
"api_url": "http://terra-testnet.lunie.io/",
"api_url": "https://terra-testnet.lunie.io",
"rpc_url": "wss://terra-testnet.lunie.io/websocket",
"bech32_prefix": "terra",
"source_class_name": "source/terraV3-source",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"testnet": true,
"feature_session": true,
"feature_explore": true,
Expand All @@ -103,11 +103,11 @@
"feature_proposals": false,
"feature_activity": true,
"feature_explorer": true,
"action_send": false,
"action_claim_rewards": false,
"action_delegate": false,
"action_redelegate": false,
"action_undelegate": false,
"action_send": true,
"action_claim_rewards": true,
"action_delegate": true,
"action_redelegate": true,
"action_undelegate": true,
"action_deposit": false,
"action_vote": false,
"action_proposal": false,
Expand All @@ -119,30 +119,30 @@
"id": "emoney-testnet",
"title": "e-Money",
"chain_id": "lilmermaid-4",
"api_url": "https://emoney-lilmermaid-4.lunie.io/",
"api_url": "https://emoney-lilmermaid-4.lunie.io",
"rpc_url": "wss://emoney-lilmermaid-4.lunie.io/websocket",
"bech32_prefix": "emoney",
"source_class_name": "source/emoneyV0-source",
"block_listener_class_name": "block-listeners/cosmos-node-subscription",
"testnet": true,
"feature_session": true,
"feature_explore": true,
"feature_portfolio": false,
"feature_portfolio": true,
"feature_validators": true,
"feature_proposals": false,
"feature_activity": false,
"feature_explorer": false,
"action_send": false,
"action_claim_rewards": false,
"action_delegate": false,
"action_redelegate": false,
"action_undelegate": false,
"feature_activity": true,
"feature_explorer": true,
"action_send": true,
"action_claim_rewards": true,
"action_delegate": true,
"action_redelegate": true,
"action_undelegate": true,
"action_deposit": false,
"action_vote": false,
"action_proposal": false,
"default": false,
"stakingDenom": "NGM",
"enabled": false
"enabled": true
},
{
"id": "livepeer-mainnet",
Expand Down Expand Up @@ -173,4 +173,4 @@
"stakingDenom": "LPT",
"enabled": false
}
]
]
10 changes: 8 additions & 2 deletions lib/controller/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ module.exports = {
broadcast
}

// TODO implment broadcasting across network types
async function broadcastTransaction(networkId, senderAddress, url, signedTx) {
// broadcast transaction with signatures included
// `block` means we wait for the tx to be included into a block before returning. this helps with figuring out "out of gas" issues which only appear when the block is created
const body = createBroadcastBody(signedTx, `sync`)
console.log('broadcast to:', url)

url = url.trim('/') // there is an error broadcasting if the URL ends with //txs
const broadcastUrl = `${url}/txs`

console.log('broadcast to:', broadcastUrl, 'with body', body)
// eslint-disable-next-line no-undef
const res = await fetch(`${url}/txs`, {
const res = await fetch(broadcastUrl, {
method: `POST`,
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -108,6 +113,7 @@ function createBroadcastBody(signedTx, returnType = `sync`) {
}

function assertOk(res) {
if (!res) throw new Error(`Error sending transaction`)
if (Array.isArray(res)) {
if (res.length === 0) throw new Error(`Error sending transaction`)

Expand Down
23 changes: 7 additions & 16 deletions lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ function proposalFinalized(proposal) {
}

function accountInfoReducer(accountValue, accountType) {
if (accountType === `cosmos-sdk/Account`) {
return {
address: accountValue.address,
accountNumber: accountValue.account_number,
sequence: accountValue.sequence
}
// here I am assuming that all three kinds of vesting accounts keep the same structure
} else if (accountType.includes(`VestingAccount`)) {
const account = accountValue.BaseVestingAccount.BaseAccount
return {
address: account.address,
accountNumber: account.account_number,
sequence: account.sequence
}
} else {
console.error('Unknown Cosmos account type')
if (accountType.includes(`VestingAccount`)) {
accountValue = accountValue.BaseVestingAccount.BaseAccount
}
return {
address: accountValue.address,
accountNumber: accountValue.account_number,
sequence: accountValue.sequence
}
}

Expand Down

0 comments on commit 2511cc9

Please sign in to comment.