|
@@ -33,9 +33,13 @@ import {
|
|
import { useSystemStore } from '@/stores/system'
|
|
import { useSystemStore } from '@/stores/system'
|
|
import _setEntropy from './wallet/setEntropy.ts'
|
|
import _setEntropy from './wallet/setEntropy.ts'
|
|
|
|
|
|
|
|
+/* Initialize constants. */
|
|
const CASHOUT_FEE = BigInt(1000) // FIXME We MUST calculate this (same as change).
|
|
const CASHOUT_FEE = BigInt(1000) // FIXME We MUST calculate this (same as change).
|
|
const TIMETOCASHOUT_HEX = '6c6c6c6c5479009c63557a7cad6d6d67547a519d537ab275030051147b7e00cd8800cc55ea537a94a2697568'
|
|
const TIMETOCASHOUT_HEX = '6c6c6c6c5479009c63557a7cad6d6d67547a519d537ab275030051147b7e00cd8800cc55ea537a94a2697568'
|
|
-const UPDATE_BALANCE_INTERVAL = 30000
|
|
|
|
|
|
+const UPDATE_BALANCE_INTERVAL = 5000
|
|
|
|
+
|
|
|
|
+/* Initialize globals. */
|
|
|
|
+let balanceHandler
|
|
|
|
|
|
/**
|
|
/**
|
|
* Wallet Store
|
|
* Wallet Store
|
|
@@ -166,11 +170,12 @@ export const useWalletStore = defineStore('wallet', {
|
|
if (System.ticker) {
|
|
if (System.ticker) {
|
|
/* Set quote. */
|
|
/* Set quote. */
|
|
const quote = System.ticker.quote
|
|
const quote = System.ticker.quote
|
|
|
|
+ console.log('QUOTE', quote)
|
|
|
|
|
|
/* Validate quote. */
|
|
/* Validate quote. */
|
|
if (quote) {
|
|
if (quote) {
|
|
/* Set (USD) price. */
|
|
/* Set (USD) price. */
|
|
- USD = quote?.USD?.price * Number(satoshis)
|
|
|
|
|
|
+ USD = (quote?.USD?.price * parseFloat(Number(satoshis) / 100))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -241,6 +246,15 @@ export const useWalletStore = defineStore('wallet', {
|
|
return _state._wallet.isReady
|
|
return _state._wallet.isReady
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ /* Return public key. */
|
|
|
|
+ publicKey(_state) {
|
|
|
|
+ if (!_state._wallet?.publicKey) {
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return _state._wallet?.publicKey
|
|
|
|
+ },
|
|
|
|
+
|
|
scriptPubkey(_state) {
|
|
scriptPubkey(_state) {
|
|
/* Initialize locals. */
|
|
/* Initialize locals. */
|
|
let constraintData
|
|
let constraintData
|
|
@@ -266,8 +280,8 @@ export const useWalletStore = defineStore('wallet', {
|
|
// console.log('TEMPLATE HASH', binToHex(scriptHash))
|
|
// console.log('TEMPLATE HASH', binToHex(scriptHash))
|
|
|
|
|
|
/* Set public key. */
|
|
/* Set public key. */
|
|
- publicKey = this._wallet.publicKey
|
|
|
|
- // console.log('PUBLIC KEY', binToHex(publicKey))
|
|
|
|
|
|
+ publicKey = this.publicKey
|
|
|
|
+ // console.log('PUBLIC KEY', publicKey)
|
|
|
|
|
|
/* Hash the public key hash according to the P2PKH/P2PKT scheme. */
|
|
/* Hash the public key hash according to the P2PKH/P2PKT scheme. */
|
|
constraintData = encodeDataPush(publicKey)
|
|
constraintData = encodeDataPush(publicKey)
|
|
@@ -298,9 +312,7 @@ export const useWalletStore = defineStore('wallet', {
|
|
scriptPubkey = new Uint8Array([
|
|
scriptPubkey = new Uint8Array([
|
|
OP.ZERO, // groupid or empty stack item
|
|
OP.ZERO, // groupid or empty stack item
|
|
...encodeDataPush(scriptHash), // script hash
|
|
...encodeDataPush(scriptHash), // script hash
|
|
- // OP.ZERO, // arguments hash or empty stack item
|
|
|
|
...encodeDataPush(constraintHash), // arguments hash
|
|
...encodeDataPush(constraintHash), // arguments hash
|
|
- // ...encodeDataPush(publicKey), // Owners public key.
|
|
|
|
...encodeDataPush(recoveryPkh), // A recovery address (specified by the Owner) used to cashout the balance, after a timeout period.
|
|
...encodeDataPush(recoveryPkh), // A recovery address (specified by the Owner) used to cashout the balance, after a timeout period.
|
|
...gratitude, // The rate of exchange, charged by the Provider. (measured in <satoshis> per <asset>)
|
|
...gratitude, // The rate of exchange, charged by the Provider. (measured in <satoshis> per <asset>)
|
|
...timeout, // The rate of exchange, charged by the Provider. (measured in <satoshis> per <asset>)
|
|
...timeout, // The rate of exchange, charged by the Provider. (measured in <satoshis> per <asset>)
|
|
@@ -348,7 +360,7 @@ export const useWalletStore = defineStore('wallet', {
|
|
console.info('(Initialized) wallet', this.wallet)
|
|
console.info('(Initialized) wallet', this.wallet)
|
|
|
|
|
|
/* Update balance. */
|
|
/* Update balance. */
|
|
- setInterval(this.updateBalance, UPDATE_BALANCE_INTERVAL)
|
|
|
|
|
|
+ balanceHandler = setInterval(this.updateBalance, UPDATE_BALANCE_INTERVAL)
|
|
this.updateBalance()
|
|
this.updateBalance()
|
|
},
|
|
},
|
|
|
|
|
|
@@ -399,7 +411,7 @@ export const useWalletStore = defineStore('wallet', {
|
|
let unlockingScript
|
|
let unlockingScript
|
|
|
|
|
|
/* Set script public key. */
|
|
/* Set script public key. */
|
|
- scriptPubkey = encodeDataPush(this._wallet.publicKey)
|
|
|
|
|
|
+ scriptPubkey = encodeDataPush(this.publicKey)
|
|
|
|
|
|
/* Set locking script. */
|
|
/* Set locking script. */
|
|
lockingScript = hexToBin(TIMETOCASHOUT_HEX)
|
|
lockingScript = hexToBin(TIMETOCASHOUT_HEX)
|
|
@@ -506,6 +518,16 @@ export const useWalletStore = defineStore('wallet', {
|
|
return this.wallet
|
|
return this.wallet
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ cleanup() {
|
|
|
|
+ console.info('Cleaning up wallet...')
|
|
|
|
+
|
|
|
|
+ /* Validate balance handler. */
|
|
|
|
+ if (balanceHandler) {
|
|
|
|
+ /* Stop balance interval. */
|
|
|
|
+ clearInterval(balanceHandler)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
destroy() {
|
|
destroy() {
|
|
/* Reset wallet. */
|
|
/* Reset wallet. */
|
|
this._entropy = null
|
|
this._entropy = null
|