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'
12 } 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'
49// const createUnsignedTxn = config => {
57// const ctrcs = contracts.matchWith({
58// Just: (cs) => cs.value,
60// throw BRIDGE_ERROR.MISSING_CONTRACTS
64// const galaxy = parseInt(ob.patp2dec(galaxyName), 10)
66// const txn = isValidGalaxy(galaxyName) && isValidAddress(galaxyOwner)
67// ? Maybe.Just(azimuth.ecliptic.createGalaxy(ctrcs, galaxy, galaxyOwner))
74const signTransaction = async config => {
88 chainId = toHex(chainId)
89 gasPrice = toHex(toWei(gasPrice, 'gwei'))
90 gasLimit = toHex(gasLimit)
92 const wal = wallet.matchWith({
95 throw BRIDGE_ERROR.MISSING_WALLET
99 const sec = wal.privateKey
101 const utx = txn.matchWith({
103 Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
105 throw BRIDGE_ERROR.MISSING_TXN
109 const stx = new Tx(utx)
111 if (walletType === WALLET_NAMES.LEDGER) {
112 await ledgerSignTransaction(stx)
117 setStx(Maybe.Just(stx))
122const sendSignedTransaction = (web3, stx) => {
123 const txn = stx.matchWith({
124 Just: (tx) => tx.value,
126 throw BRIDGE_ERROR.MISSING_TXN
130 const serializedTx = addHexPrefix(txn.serialize().toString('hex'))
132 return new Promise((resolve, reject) => {
133 web3.eth.sendSignedTransaction(serializedTx)
134 .on('receipt', txn =>
135 resolve(Maybe.Just(Result.Ok(txn)))
137 .on('error', err => {
138 reject(Maybe.Just(Result.Error(err.message)))
143const hexify = val => addHexPrefix(val.toString('hex'))
145const renderSignedTx = stx => ({
146 messageHash: hexify(stx.hash()),
150 rawTransaction: hexify(stx.serialize())
153const getTxnInfo = async (web3, addr) => {
154 let nonce = await web3.eth.getTransactionCount(addr)
155 let chainId = await web3.eth.net.getId()
156 let gasPrice = await web3.eth.getGasPrice()
160 gasPrice: fromWei(gasPrice, 'gwei')
164const dummy = new Web3()
165const toHex = dummy.utils.toHex
166const toWei = dummy.utils.toWei
167const fromWei = dummy.utils.fromWei
170// const confirmShipAvailability = (point, contracts) => {
172// if (canDecodePatp(point) === true) {
174// const pointDec = ob.patp2dec(point)
176// contracts.matchWith({
178// throw BRIDGE_ERROR.MISSING_CONTRACTS
180// Just: async (contracts) => {
181// const owner = await azimuth.azimuth.getOwner(contracts.value, point)
182// if (eqAddr(owner, ETH_ZERO_ADDR)) return true
191const canDecodePatp = p => {
204// const bridgeAPI = {
205// shipAvailability: {
206// planet: planet => {},
208// galaxy: galaxy => {},
217 sendSignedTransaction,
227 // 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