1import * as ob from 'urbit-ob'
2import Maybe from 'folktale/maybe'
3import Result from 'folktale/result'
4import Tx from 'ethereumjs-tx'
7import { BRIDGE_ERROR } from '../lib/error'
8import { ledgerSignTransaction } from '../lib/ledger'
9import { trezorSignTransaction } from '../lib/trezor'
13 } from '../lib/wallet'
16 SET_MANAGEMENT_PROXY: Symbol('SET_MANAGEMENT_PROXY'),
17 SET_TRANSFER_PROXY: Symbol('SET_TRANSFER_PROXY'),
18 SET_SPAWN_PROXY: Symbol('SET_SPAWN_PROXY'),
19 CREATE_GALAXY: Symbol('CREATE_GALAXY'),
20 ISSUE_CHILD: Symbol('ISSUE_CHILD'),
21 SET_KEYS: Symbol('SET_KEYS'),
22 TRANSFER: Symbol('TRANSFER'),
23 CANCEL_TRANSFER: Symbol('CANCEL_TRANSFER')
26const renderTxnPurpose = (purpose) =>
27 purpose === TXN_PURPOSE.SET_MANAGEMENT_PROXY
28 ? 'set this management proxy'
29 : purpose === TXN_PURPOSE.SET_SPAWN_PROXY
30 ? 'set this spawn proxy'
31 : purpose === TXN_PURPOSE.SET_TRANSFER_PROXY
32 ? 'set this transfer proxy'
33 : purpose === TXN_PURPOSE.CREATE_GALAXY
34 ? 'create this galaxy'
35 : purpose === TXN_PURPOSE.ISSUE_CHILD
37 : purpose === TXN_PURPOSE.SET_KEYS
38 ? 'set these network keys'
39 : purpose === TXN_PURPOSE.TRANSFER
40 ? 'transfer this point'
41 : purpose === TXN_PURPOSE.CANCEL_TRANSFER
42 ? 'cancel this transfer'
43 : 'perform this transaction'
45const signTransaction = async config => {
60 chainId = toHex(chainId)
61 gasPrice = toHex(toWei(gasPrice, 'gwei'))
62 gasLimit = toHex(gasLimit)
64 const wal = wallet.matchWith({
66 Nothing: () => { throw BRIDGE_ERROR.MISSING_WALLET }
69 const sec = wal.privateKey
71 const utx = txn.matchWith({
73 Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
75 throw BRIDGE_ERROR.MISSING_TXN
79 const stx = new Tx(utx)
81 if (walletType === WALLET_NAMES.LEDGER) {
82 await ledgerSignTransaction(stx, walletHdPath)
83 } else if (walletType === WALLET_NAMES.TREZOR) {
84 await trezorSignTransaction(stx, walletHdPath)
89 setStx(Maybe.Just(stx))
92const sendSignedTransaction = (web3, stx) => {
93 const txn = stx.matchWith({
94 Just: (tx) => tx.value,
96 throw BRIDGE_ERROR.MISSING_TXN
100 const serializedTx = addHexPrefix(txn.serialize().toString('hex'))
102 return new Promise((resolve, reject) => {
103 web3.eth.sendSignedTransaction(serializedTx)
104 .on('receipt', txn =>
105 resolve(Maybe.Just(Result.Ok(txn)))
107 .on('error', err => {
108 reject(Maybe.Just(Result.Error(err.message)))
113const hexify = val => addHexPrefix(val.toString('hex'))
115const renderSignedTx = stx => ({
116 messageHash: hexify(stx.hash()),
120 rawTransaction: hexify(stx.serialize())
123const getTxnInfo = async (web3, addr) => {
124 let nonce = await web3.eth.getTransactionCount(addr)
125 let chainId = await web3.eth.net.getId()
126 let gasPrice = await web3.eth.getGasPrice()
130 gasPrice: fromWei(gasPrice, 'gwei')
134const dummy = new Web3()
135const toHex = dummy.utils.toHex
136const toWei = dummy.utils.toWei
137const fromWei = dummy.utils.fromWei
139const canDecodePatp = p => {
150 sendSignedTransaction,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list