|
@@ -1,6 +1,7 @@
|
|
|
<script setup lang="ts">
|
|
|
/* Import modules. */
|
|
|
import numeral from 'numeral'
|
|
|
+import signSharedTx from '../handlers/signSharedTx.ts'
|
|
|
|
|
|
/* Define properties. */
|
|
|
// https://vuejs.org/guide/components/props.html#props-declaration
|
|
@@ -20,6 +21,7 @@ const hushAddresses = ref(null)
|
|
|
const nexaAddresses = ref(null)
|
|
|
|
|
|
const HUSH_PROTOCOL_ID = 0x48555348
|
|
|
+const DUST_VAL = 546
|
|
|
|
|
|
const balance = computed(() => {
|
|
|
if (!Wallet.fusionInputs) {
|
|
@@ -34,8 +36,88 @@ const balance = computed(() => {
|
|
|
return numeral(totalValue).format('0,0')
|
|
|
})
|
|
|
|
|
|
-const cashout = () => {
|
|
|
- alert('WIP?? sorry...')
|
|
|
+const cashout = async () => {
|
|
|
+ // alert('WIP?? sorry...')
|
|
|
+
|
|
|
+ /* Initialize locals. */
|
|
|
+ let inputs
|
|
|
+ let keys
|
|
|
+ let outputs
|
|
|
+ let rawTx
|
|
|
+ let response
|
|
|
+ let session
|
|
|
+
|
|
|
+ // FIXME
|
|
|
+ const sessionid = '4e9654f9-3de9-4f9a-8169-3834f40847f5'
|
|
|
+
|
|
|
+ /* Request session details. */
|
|
|
+ session = await $fetch(`http://localhost:39159/v1/fusion/${sessionid}`)
|
|
|
+ .catch(err => console.error(err))
|
|
|
+ console.log('SESSION', session)
|
|
|
+
|
|
|
+ /* Set inputs. */
|
|
|
+ inputs = session.inputs
|
|
|
+ // console.log('INPUTS', inputs)
|
|
|
+
|
|
|
+ /* Initialize keys. */
|
|
|
+ keys = []
|
|
|
+
|
|
|
+ /* Handle (input) keys. */
|
|
|
+ Object.keys(inputs).forEach(_inputid => {
|
|
|
+ keys.push(_inputid)
|
|
|
+ })
|
|
|
+ // console.log('KEYS', keys)
|
|
|
+
|
|
|
+ /* Sort (input) keys. */
|
|
|
+ keys.sort()
|
|
|
+ // console.log('KEYS (sorted)', keys)
|
|
|
+
|
|
|
+ /* Initialize sorted inputs. */
|
|
|
+ const sortedInputs = []
|
|
|
+
|
|
|
+ /* Handle (input) keys. */
|
|
|
+ keys.forEach(_keyid => {
|
|
|
+ /* Add input. */
|
|
|
+ sortedInputs.push(inputs[_keyid])
|
|
|
+ })
|
|
|
+ // console.log('INPUTS (sorted)', sortedInputs)
|
|
|
+
|
|
|
+ outputs = session.outputs
|
|
|
+ // console.log('OUTPUTS', outputs)
|
|
|
+
|
|
|
+ /* Initialize (output) keys. */
|
|
|
+ keys = []
|
|
|
+
|
|
|
+ /* Handle keys. */
|
|
|
+ Object.keys(outputs).forEach(_outputid => {
|
|
|
+ keys.push(_outputid)
|
|
|
+ })
|
|
|
+ // console.log('KEYS', keys)
|
|
|
+
|
|
|
+ /* Sort (output) keys. */
|
|
|
+ keys.sort()
|
|
|
+ // console.log('KEYS (sorted)', keys)
|
|
|
+
|
|
|
+ /* Initialize sorted outputs. */
|
|
|
+ const sortedOutputs = []
|
|
|
+
|
|
|
+ /* Handle (output) keys. */
|
|
|
+ keys.forEach(_keyid => {
|
|
|
+ if (outputs[_keyid].value >= DUST_VAL) {
|
|
|
+ /* Add input. */
|
|
|
+ sortedOutputs.push(outputs[_keyid])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // console.log('OUTPUTS (sorted)', sortedOutputs)
|
|
|
+
|
|
|
+ /* Sign shared transaction. */
|
|
|
+ rawTx = signSharedTx(
|
|
|
+ sessionid, Wallet.mnemonic, sortedInputs, sortedOutputs)
|
|
|
+ console.log('RAW TX', rawTx)
|
|
|
+
|
|
|
+ response = await Wallet.broadcast('BCH', rawTx)
|
|
|
+ .catch(err => console.error(err))
|
|
|
+ console.log('BROADCAST (response)', response)
|
|
|
}
|
|
|
|
|
|
const consolidate = () => {
|
|
@@ -64,7 +146,7 @@ const init = () => {
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
- console.log('KEYCHAIN', Wallet.keychain)
|
|
|
+ // console.log('KEYCHAIN', Wallet.keychain)
|
|
|
// init()
|
|
|
setTimeout(init, 1000)
|
|
|
})
|