-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aepp,wallet): support inner transaction signing
- Loading branch information
Showing
9 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<template> | ||
<GenerateSpendTx /> | ||
|
||
<h2>Sign inner transaction</h2> | ||
<div class="group"> | ||
<div> | ||
<div>Transaction</div> | ||
<div> | ||
<input | ||
v-model="txToPayFor" | ||
placeholder="tx_..." | ||
> | ||
</div> | ||
</div> | ||
<button @click="signInnerTxPromise = signInnerTx()"> | ||
Sign | ||
</button> | ||
<div v-if="signInnerTxPromise"> | ||
<div>Signed inner transaction</div> | ||
<Value :value="signInnerTxPromise" /> | ||
</div> | ||
</div> | ||
|
||
<h2>Pay for transaction</h2> | ||
<div class="group"> | ||
<div> | ||
<div>Signed inner transaction</div> | ||
<div> | ||
<input | ||
v-model="innerTx" | ||
placeholder="tx_..." | ||
> | ||
</div> | ||
</div> | ||
<button @click="payForTxPromise = payForTx()"> | ||
Pay for transaction | ||
</button> | ||
<div v-if="payForTxPromise"> | ||
<div>Result</div> | ||
<Value :value="payForTxPromise" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapState } from 'vuex'; | ||
import Value from './components/Value.vue'; | ||
import SpendCoins from './components/SpendCoins.vue'; | ||
import MessageSign from './components/MessageSign.vue'; | ||
import GenerateSpendTx from './components/GenerateSpendTx.vue'; | ||
export default { | ||
components: { | ||
Value, SpendCoins, MessageSign, GenerateSpendTx, | ||
}, | ||
data: () => ({ | ||
innerTx: '', | ||
txToPayFor: '', | ||
signInnerTxPromise: null, | ||
payForTxPromise: null, | ||
}), | ||
computed: mapState(['aeSdk']), | ||
methods: { | ||
signInnerTx() { | ||
return this.aeSdk.signTransaction(this.txToPayFor, { innerTx: true }); | ||
}, | ||
payForTx() { | ||
return this.aeSdk.payForTransaction(this.innerTx); | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<h2>Generate spend transaction</h2> | ||
<div class="group"> | ||
<div> | ||
<div>Recipient address</div> | ||
<div> | ||
<input | ||
v-model="spendTo" | ||
placeholder="ak_..." | ||
> | ||
</div> | ||
</div> | ||
<div> | ||
<div>Coins amount</div> | ||
<div><input v-model="spendAmount"></div> | ||
</div> | ||
<div> | ||
<div>Payload</div> | ||
<div><input v-model="spendPayload"></div> | ||
</div> | ||
<div> | ||
<div>Increment nonce by 1</div> | ||
<div> | ||
<input | ||
type="checkbox" | ||
v-model="incrementNonce" | ||
> | ||
(only if you want to pay for this transaction yourself) | ||
</div> | ||
</div> | ||
<button @click="generatePromise = generate()"> | ||
Generate | ||
</button> | ||
<div v-if="generatePromise"> | ||
<div>Spend transaction</div> | ||
<Value :value="generatePromise" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapState } from 'vuex'; | ||
import { | ||
encode, Encoding, Tag, unpackTx, buildTx, | ||
} from '@aeternity/aepp-sdk'; | ||
import Value from './Value.vue'; | ||
export default { | ||
components: { Value }, | ||
data: () => ({ | ||
spendTo: '', | ||
spendAmount: '', | ||
spendPayload: '', | ||
incrementNonce: true, | ||
generatePromise: null, | ||
}), | ||
computed: mapState(['aeSdk']), | ||
methods: { | ||
async generate() { | ||
let spendTx = await this.aeSdk.buildTx({ | ||
tag: Tag.SpendTx, | ||
senderId: this.aeSdk.address, | ||
recipientId: this.spendTo, | ||
amount: this.spendAmount, | ||
payload: encode(new TextEncoder().encode(this.spendPayload), Encoding.Bytearray), | ||
}); | ||
if (this.incrementNonce) { | ||
const spendTxParams = unpackTx(spendTx); | ||
spendTxParams.nonce += 1; | ||
spendTx = buildTx(spendTxParams); | ||
} | ||
return spendTx; | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters