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'
17 SET_MANAGEMENT_PROXY: Symbol('SET_MANAGEMENT_PROXY'),
18 SET_TRANSFER_PROXY: Symbol('SET_TRANSFER_PROXY'),
19 SET_SPAWN_PROXY: Symbol('SET_SPAWN_PROXY'),
20 CREATE_GALAXY: Symbol('CREATE_GALAXY'),
21 ISSUE_CHILD: Symbol('ISSUE_CHILD'),
22 SET_KEYS: Symbol('SET_KEYS'),
23 TRANSFER: Symbol('TRANSFER'),
24 CANCEL_TRANSFER: Symbol('CANCEL_TRANSFER')
27const renderTxnPurpose = (purpose) =>
28 purpose === TXN_PURPOSE.SET_MANAGEMENT_PROXY
29 ? 'set this management proxy'
30 : purpose === TXN_PURPOSE.SET_SPAWN_PROXY
31 ? 'set this spawn proxy'
32 : purpose === TXN_PURPOSE.SET_TRANSFER_PROXY
33 ? 'set this transfer proxy'
34 : purpose === TXN_PURPOSE.CREATE_GALAXY
35 ? 'create this galaxy'
36 : purpose === TXN_PURPOSE.ISSUE_CHILD
38 : purpose === TXN_PURPOSE.SET_KEYS
39 ? 'set these network keys'
40 : purpose === TXN_PURPOSE.TRANSFER
41 ? 'transfer this point'
42 : purpose === TXN_PURPOSE.CANCEL_TRANSFER
43 ? 'cancel this transfer'
44 : 'perform this transaction'
50// const createUnsignedTxn = config => {
58// const ctrcs = contracts.matchWith({
59// Just: (cs) => cs.value,
61// throw BRIDGE_ERROR.MISSING_CONTRACTS
65// const galaxy = parseInt(ob.patp2dec(galaxyName), 10)
67// const txn = isValidGalaxy(galaxyName) && isValidAddress(galaxyOwner)
68// ? Maybe.Just(azimuth.ecliptic.createGalaxy(ctrcs, galaxy, galaxyOwner))
75const signTransaction = async config => {
90 chainId = toHex(chainId)
91 gasPrice = toHex(toWei(gasPrice, 'gwei'))
92 gasLimit = toHex(gasLimit)
94 const wal = wallet.matchWith({
97 throw BRIDGE_ERROR.MISSING_WALLET
101 const sec = wal.privateKey
103 const utx = txn.matchWith({
105 Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
107 throw BRIDGE_ERROR.MISSING_TXN
111 const stx = new Tx(utx)
113 if (walletType === WALLET_NAMES.LEDGER) {
114 await ledgerSignTransaction(stx, walletHdPath)
115 } else if (walletType === WALLET_NAMES.TREZOR) {
116 await trezorSignTransaction(stx, walletHdPath)
121 setStx(Maybe.Just(stx))
126const sendSignedTransaction = (web3, stx) => {
127 const txn = stx.matchWith({
128 Just: (tx) => tx.value,
130 throw BRIDGE_ERROR.MISSING_TXN
134 const serializedTx = addHexPrefix(txn.serialize().toString('hex'))
136 return new Promise((resolve, reject) => {
137 web3.eth.sendSignedTransaction(serializedTx)
138 .on('receipt', txn =>
139 resolve(Maybe.Just(Result.Ok(txn)))
141 .on('error', err => {
142 reject(Maybe.Just(Result.Error(err.message)))
147const hexify = val => addHexPrefix(val.toString('hex'))
149const renderSignedTx = stx => ({
150 messageHash: hexify(stx.hash()),
154 rawTransaction: hexify(stx.serialize())
157const getTxnInfo = async (web3, addr) => {
158 let nonce = await web3.eth.getTransactionCount(addr)
159 let chainId = await web3.eth.net.getId()
160 let gasPrice = await web3.eth.getGasPrice()
164 gasPrice: fromWei(gasPrice, 'gwei')
168const dummy = new Web3()
169const toHex = dummy.utils.toHex
170const toWei = dummy.utils.toWei
171const fromWei = dummy.utils.fromWei
174// const confirmShipAvailability = (point, contracts) => {
176// if (canDecodePatp(point) === true) {
178// const pointDec = ob.patp2dec(point)
180// contracts.matchWith({
182// throw BRIDGE_ERROR.MISSING_CONTRACTS
184// Just: async (contracts) => {
185// const owner = await azimuth.azimuth.getOwner(contracts.value, point)
186// if (eqAddr(owner, ETH_ZERO_ADDR)) return true
195const canDecodePatp = p => {
208// const bridgeAPI = {
209// shipAvailability: {
210// planet: planet => {},
212// galaxy: galaxy => {},
221 sendSignedTransaction,
231 // confirmShipAvailability,
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