on master help sign in
refactor: tiny refactor for converting point names into points before deriving wallets
commitca6ebb8b2a17501dd39490806cd9595c21c02810 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 9 Jul 2019, 15:31 (7 years ago) parent217f1b6
4 files changed+12−34
src/lib/invite.js+5−7 src/lib/wallet.js−18 src/lib/walletgen.js+1 src/views/Login/Ticket.js+6−9
src/lib/invite.js+5−7
@@ -99,8 +99,6 @@ export async function reticketPointBetweenWallets({
9999 const gotFunding = () => onUpdate({ type: 'gotFunding' });
100100 const progress = state => onUpdate({ type: 'progress', state });
101101
102− const inviteAddress = fromWallet.address;
103−
104102 //
105103 // generate transactions
106104 //
@@ -117,7 +115,7 @@ export async function reticketPointBetweenWallets({
117115 const transferTmpTx = azimuth.ecliptic.transferPoint(
118116 contracts,
119117 point,
120− inviteAddress,
118+ fromWallet.address,
121119 false
122120 );
123121 transferTmpTx.gas = GAS_LIMITS.TRANSFER;
@@ -201,9 +199,9 @@ export async function reticketPointBetweenWallets({
201199 progress(TRANSACTION_STATES.SIGNING);
202200
203201 let totalCost = 0;
204− let inviteNonce = await web3.eth.getTransactionCount(inviteAddress);
202+ let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
205203 txs = txs.map(tx => {
206− tx.from = inviteAddress;
204+ tx.from = fromWallet.address;
207205 tx.nonce = inviteNonce++;
208206 tx.gasPrice = 20000000000; //NOTE we pay the premium for faster ux
209207 totalCost = totalCost + tx.gasPrice * tx.gas;
@@ -228,7 +226,7 @@ export async function reticketPointBetweenWallets({
228226 const usedTank = await tank.ensureFundsFor(
229227 web3,
230228 point,
231− inviteAddress,
229+ fromWallet.address,
232230 totalCost,
233231 txPairs.map(p => p.raw),
234232 askForFunding,
@@ -254,7 +252,7 @@ export async function reticketPointBetweenWallets({
254252 progress(TRANSACTION_STATES.CLEANING);
255253
256254 // if non-trivial eth left in invite wallet, transfer to new ownership
257− let balance = await web3.eth.getBalance(inviteAddress);
255+ let balance = await web3.eth.getBalance(fromWallet.address);
258256 const gasPrice = 20000000000;
259257 const gasLimit = 21000;
260258 const sendEthCost = gasPrice * gasLimit;
src/lib/wallet.js−18
@@ -74,11 +74,6 @@ export const eqAddr = (addr0, addr1) =>
7474 toChecksumAddress(addr0) === toChecksumAddress(addr1);
7575
7676export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
77− if (typeof point === 'string') {
78− //TODO why not in kg?
79− point = ob.patp2dec(point);
80− }
81−
8277 return await kg.generateWallet({
8378 ticket: ticket,
8479 ship: point,
@@ -86,19 +81,6 @@ export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
8681 });
8782};
8883
89−export const ownershipWalletFromTicket = async (ticket, point, passphrase) => {
90− if (typeof point === 'string') {
91− //TODO why not in kg?
92− point = ob.patp2dec(point);
93− }
94−
95− return await kg.generateOwnershipWallet({
96− ticket,
97− ship: point,
98− passphrase,
99− });
100−};
101−
10284export const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
10385 const seed = bip39.validateMnemonic(mnemonic)
10486 ? Just(bip39.mnemonicToSeed(mnemonic, passphrase))
src/lib/walletgen.js+1
@@ -71,6 +71,7 @@ export const generateOwnershipWallet = (ship, ticket) =>
7171// so we always use ~zod as the wallet point.
7272export const generateTemporaryOwnershipWallet = ticket =>
7373 generateOwnershipWallet(ZOD, ticket);
74+
7475export const generateTemporaryTicketAndWallet = async point => {
7576 const ticket = await makeTicket(point);
7677 const owner = await generateOwnershipWallet(ZOD, ticket);
src/views/Login/Ticket.js+6−9
@@ -94,21 +94,17 @@ export default function Ticket({ className }) {
9494 }
9595
9696 const _contracts = need.contracts(contracts);
97− const pointNumber = ob.patp2dec(pointName);
98− const urbitWallet = await urbitWalletFromTicket(
99− ticket,
100− pointName,
101− passphrase
102− );
97+ const point = ob.patp2dec(pointName);
98+ const urbitWallet = await urbitWalletFromTicket(ticket, point, passphrase);
10399 const [isOwner, isTransferProxy] = await Promise.all([
104100 azimuth.azimuth.isOwner(
105101 _contracts,
106− pointNumber,
102+ point,
107103 urbitWallet.ownership.keys.address
108104 ),
109105 azimuth.azimuth.isTransferProxy(
110106 _contracts,
111− pointNumber,
107+ point,
112108 urbitWallet.ownership.keys.address
113109 ),
114110 ]);
@@ -140,7 +136,8 @@ export default function Ticket({ className }) {
140136
141137 try {
142138 const ticket = kg.combine([s1, s2, s3]);
143− const uhdw = await urbitWalletFromTicket(ticket, pointName, passphrase);
139+ const point = ob.patp2dec(pointName);
140+ const uhdw = await urbitWalletFromTicket(ticket, point, passphrase);
144141 setUrbitWallet(Just(uhdw));
145142 } catch (_) {
146143 // do nothing