Skip to content

Commit

Permalink
Merge pull request #10 from nothingalike/hotfix/cli-issue-with-spaces
Browse files Browse the repository at this point in the history
Updated Production App Paths
  • Loading branch information
nothingalike authored Jan 19, 2021
2 parents 65e9144 + f7ca816 commit 9b790c4
Show file tree
Hide file tree
Showing 8 changed files with 17,617 additions and 44 deletions.
17,562 changes: 17,547 additions & 15 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lift-wallet",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
4 changes: 2 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ ipcMain.on('req:get-fee', async (event, args) => {
})

ipcMain.on('req:send-transaction', async (event, args) => {
const result = await sendTransaction(args.network, args.wallet, args.amount, args.address, args.passphrase);

const result = await sendTransaction(args.network, args.wallet, args.amount, args.address, args.passphrase, args.metadata);
event.reply('res:send-transaction', { transaction: result });
})

ipcMain.on('req:get-transactions', async (event, args) => {

//const transactions = await getTransactions(args.walletId);
const transactions = await getTransactions(args.network, args.wallet);
event.reply('res:get-transactions', { transactions: transactions });
Expand Down
20 changes: 19 additions & 1 deletion src/components/wallet/WalletDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
@focus="passphraseFocusIn"
>
</v-text-field>

<v-file-input
v-model="sendForm.metadataFile"
label="Metadata File">
</v-file-input>
</v-card-text>
<v-card-actions>
<v-btn
Expand Down Expand Up @@ -188,6 +193,7 @@
total: 0,
totalFormatted: '0.000000',
passphrase: '',
metadataFile: null,
validAddress: true,
validPassphrase: true,
validAmount: true
Expand Down Expand Up @@ -416,7 +422,19 @@
if (!this.$v.$invalid) {
console.log('valid')
this.isSendingAda = true;
ipcRenderer.send('req:send-transaction', { network: 'testnet', wallet: this.walletId, address: this.sendForm.address, amount: this.sendForm.amount*1000000, passphrase: this.sendForm.passphrase})
let metadata = null;
if(this.sendForm.metadataFile != null) metadata = this.sendForm.metadataFile.path;
console.log(metadata)
ipcRenderer.send(
'req:send-transaction',
{
network: 'testnet',
wallet: this.walletId,
address: this.sendForm.address,
amount: this.sendForm.amount*1000000,
passphrase: this.sendForm.passphrase,
metadata: metadata
})
}
},
getFormattedDate(txDate){
Expand Down
12 changes: 6 additions & 6 deletions src/core/cardano-addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ export const cardanoPath = isDevelopment

export function getMnemonicCmd(size){
const addressCli = path.resolve('.', cardanoPath, process.platform, 'cardano-address');
return `${addressCli} recovery-phrase generate --size ${size}`;
return `"${addressCli}" recovery-phrase generate --size ${size}`;
}

export function getRootCmd(mnemonic) {
const addressCli = path.resolve('.', cardanoPath, process.platform, 'cardano-address');
return `echo ${mnemonic} | ${addressCli} key from-recovery-phrase Shelley`;
return `echo ${mnemonic} | "${addressCli}" key from-recovery-phrase Shelley`;
}

export function getChildCmd(stdIn, derivation) {
const addressCli = path.resolve('.', cardanoPath, process.platform, 'cardano-address');
return `echo ${stdIn}| ${addressCli} key child ${derivation}`;
return `echo ${stdIn}| "${addressCli}" key child ${derivation}`;
}

export function getPublicCmd(prvKey) {
const addressCli = path.resolve('.', cardanoPath, process.platform, 'cardano-address');
return `echo ${prvKey}| ${addressCli} key public --with-chain-code`;
return `echo ${prvKey}| "${addressCli}" key public --with-chain-code`;
}

export function getBaseAddrCmd(pubKey, network){
const addressCli = path.resolve('.', cardanoPath, process.platform, 'cardano-address');
return `echo ${pubKey}| ${addressCli} address payment --network-tag ${network}`;
return `echo ${pubKey}| "${addressCli}" address payment --network-tag ${network}`;
}

export function getPaymentAddrCmd(baseAddr, stakePub){
const addressCli = path.resolve('.', cardanoPath, process.platform, 'cardano-address');
return `echo ${baseAddr}| ${addressCli} address delegation "${stakePub}"`;
return `echo ${baseAddr}| "${addressCli}" address delegation "${stakePub}"`;
}
14 changes: 9 additions & 5 deletions src/core/cardano-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export function buildTxIn(addressUtxos, amount, fee) {
return txIn;
}

export function buildTransaction(era, fee, ttl, toAddress, amount, changeAddress, txIns, outputFile){
let tx = `cardano-cli transaction build-raw --${era} --fee ${parseInt(fee)} --ttl ${parseInt(ttl)}`;
export function buildTransaction(era, fee, ttl, toAddress, amount, changeAddress, txIns, metadataPath, outputFile){
const cardanoCli = path.resolve('.', cardanoPath, process.platform, 'cardano-cli');
let tx = `"${cardanoCli}" transaction build-raw --${era} --fee ${parseInt(fee)} --ttl ${parseInt(ttl)}`;
let totalUsed = 0;
for(let txIn of txIns)
{
Expand All @@ -31,12 +32,14 @@ export function buildTransaction(era, fee, ttl, toAddress, amount, changeAddress
let change = parseInt(totalUsed) - parseInt(amount) - parseInt(fee);
if(change < 0) change = 0;
tx += ` --tx-out ${changeAddress}+${change}`;
if(metadataPath != null) tx += ` --metadata-json-file "${metadataPath}"`;
tx += ` --out-file "${outputFile}"`;
return tx;
}

export function calculateMinFee(txBody, utxoInCount, utxoOutCount, witness, byronWitness, protocolParamsFile) {
let txFee = 'cardano-cli transaction calculate-min-fee';
const cardanoCli = path.resolve('.', cardanoPath, process.platform, 'cardano-cli');
let txFee = `"${cardanoCli}" transaction calculate-min-fee`;
txFee += ` --tx-body-file "${txBody}"`;
txFee += ` --tx-in-count ${utxoInCount}`;
txFee += ` --tx-out-count ${utxoOutCount}`;
Expand All @@ -47,10 +50,11 @@ export function calculateMinFee(txBody, utxoInCount, utxoOutCount, witness, byro
}

export function signTransaction(network, magic, paymentSigningFile, changeSigningFile, rawTxBody, signTxFile) {
//sign the transaction
const cardanoCli = path.resolve('.', cardanoPath, process.platform, 'cardano-cli');

if(network == 'testnet') network = 'testnet-magic';

let txSign = 'cardano-cli transaction sign';
let txSign = `"${cardanoCli}" transaction sign`;
txSign += ` --${network}`;
if(magic != null) txSign += ` ${magic}`;
txSign += ` --signing-key-file "${paymentSigningFile}"`;
Expand Down
8 changes: 6 additions & 2 deletions src/core/dandelion.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export async function submitTransaction(network, signedTxBinary) {
var sendResult = await axios(
{
method: 'post',
url: `${getSubmitApiUrl(network)}api/submit/tx`,
url: `${getOpenFaasUrl()}function/${network}-cardano-cli`,
data: signedTxBinary,
headers: {
"Content-Type": "application/cbor"
"Content-Type": "application/json"
}
});
return sendResult.data;
Expand Down Expand Up @@ -70,6 +70,10 @@ function getPostgrestApiUrl(network) {
return `https://postgrest-api.${network}.dandelion.link/`;
}

function getOpenFaasUrl() {
return `http://openfaas.dandelion.link/`;
}

function getGraphqlList(list) {
let result = '[';
list.forEach(a => {
Expand Down
39 changes: 27 additions & 12 deletions src/services/wallet.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import lib from 'cardano-crypto.js'

const cmd = util.promisify(exec);

const walletPath = path.resolve(__dirname, '..', 'cardano', 'wallets');
const isDevelopment = process.env.NODE_ENV !== 'production'
const appPath = path.resolve(process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share"), 'lift-wallet');
const walletPath = isDevelopment
? path.resolve(__dirname, '..', 'cardano', 'wallets')
: path.resolve(appPath , 'wallets');

const accountPrvFile = 'account.xprv';
const accountPubFile = 'account.xpub';
Expand All @@ -40,6 +44,16 @@ const rawTxFile = 'raw.tx';
const signedTxFile = 'signed.tx';

export async function setupWalletDir() {
if(!isDevelopment) {
if(!fs.existsSync(appPath)) {
fs.mkdirSync(appPath);
}
}

if(!fs.existsSync(walletPath)){
fs.mkdirSync(walletPath);
}

if(!fs.existsSync(path.resolve(walletPath, 'testnet')))
fs.mkdirSync(path.resolve(walletPath, 'testnet'))

Expand Down Expand Up @@ -172,7 +186,7 @@ export async function getFee(network, name, amount, toAddress) {
let draftTxIns = buildTxIn(addressUtxos, amount, 0);

//build draft transaction
let draftTx = buildTransaction('allegra-era', 0, 0, toAddress, amount, changes[0].address, draftTxIns, txDraftPath)
let draftTx = buildTransaction('allegra-era', 0, 0, toAddress, amount, changes[0].address, draftTxIns, null, txDraftPath)
await cli(draftTx);

//get protocol parameters
Expand All @@ -193,7 +207,7 @@ export async function getFee(network, name, amount, toAddress) {
return feeResult.stdout.split(' ')[0];
}

export async function sendTransaction(network, name, amount, toAddress, passphrase) {
export async function sendTransaction(network, name, amount, toAddress, passphrase, metadataPath) {
const walletDir = path.resolve(walletPath, network, name);

//tx/key file paths
Expand All @@ -218,7 +232,7 @@ export async function sendTransaction(network, name, amount, toAddress, passphra
let draftTxIns = buildTxIn(addressUtxos, amount, 0);

//build draft transaction
let draftTx = buildTransaction('allegra-era', 0, 0, toAddress, amount, changes[0].address, draftTxIns, txDraftPath)
let draftTx = buildTransaction('allegra-era', 0, 0, toAddress, amount, changes[0].address, draftTxIns, metadataPath, txDraftPath)
await cli(draftTx);

//get protocol parameters
Expand Down Expand Up @@ -246,8 +260,7 @@ export async function sendTransaction(network, name, amount, toAddress, passphra
let rawTxIns = buildTxIn(addressUtxos, amount, fee);

//build raw transaction
let rawTx = buildTransaction('allegra-era', fee, ttl, toAddress, amount, changes[0].address, rawTxIns, txRawPath)
console.log(rawTx);
let rawTx = buildTransaction('allegra-era', fee, ttl, toAddress, amount, changes[0].address, rawTxIns, metadataPath, txRawPath)
await cli(rawTx);

//create signing keys
Expand Down Expand Up @@ -289,12 +302,14 @@ export async function sendTransaction(network, name, amount, toAddress, passphra

//send transaction
//get signed tx binary
var dataHex = JSON.parse(fs.readFileSync(txSignedPath)).cborHex
var dataBinary = getBinaryFromHexString(dataHex)
// var dataHex = JSON.parse(fs.readFileSync(txSignedPath)).cborHex
// var dataBinary = getBinaryFromHexString(dataHex)
var signedtxContents = JSON.parse(fs.readFileSync(txSignedPath));

//submit transaction to dandelion
result.transactionId = await submitTransaction(network, dataBinary);
result.transactionId = await submitTransaction(network, signedtxContents);
}catch(err) {
console.error(err);
if(err.response.data != undefined) {
console.log(err.response.data);
result.error = err.response.data;
Expand Down Expand Up @@ -382,6 +397,6 @@ function getBufferHexFromFile(hex) {
return lib.bech32.decode(hex).data.toString('hex');
}

function getBinaryFromHexString(hexString) {
return new Uint8Array(hexString.match(/.{1,2}/g).map(b => parseInt(b, 16)));
}
// function getBinaryFromHexString(hexString) {
// return new Uint8Array(hexString.match(/.{1,2}/g).map(b => parseInt(b, 16)));
// }

0 comments on commit 9b790c4

Please sign in to comment.