From 15e71cbb91535027bfbafad55de0a78a19353188 Mon Sep 17 00:00:00 2001 From: Surinder Singh Matoo Date: Wed, 15 Jun 2022 22:16:26 +0530 Subject: [PATCH] COINBASE_CFM_COUNT --- index.ts | 4 ++-- wallet/tx-store.ts | 5 ++++- wallet/utxo.ts | 5 +++-- wallet/wallet.ts | 7 ++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/index.ts b/index.ts index c899537..2e03f2c 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,8 @@ import {log, FlowLogger} from "./utils/logger"; -import {Wallet, Storage, kaspacore, CONFIRMATION_COUNT} from "./wallet/wallet"; +import {Wallet, Storage, kaspacore, CONFIRMATION_COUNT, COINBASE_CFM_COUNT} from "./wallet/wallet"; import {initKaspaFramework} from './wallet/initKaspaFramework'; import {EventTargetImpl} from './wallet/event-target-impl'; import * as helper from './utils/helper'; -export {CONFIRMATION_COUNT}; +export {CONFIRMATION_COUNT, COINBASE_CFM_COUNT}; export {Wallet, initKaspaFramework, log, EventTargetImpl, helper, Storage, FlowLogger, kaspacore} \ No newline at end of file diff --git a/wallet/tx-store.ts b/wallet/tx-store.ts index 6b9b9b9..7bc6cc4 100644 --- a/wallet/tx-store.ts +++ b/wallet/tx-store.ts @@ -12,6 +12,7 @@ export interface TXStoreItem{ note?:string; tx?:any, myAddress?:boolean, + isCoinbase:boolean, isMoved?:boolean } @@ -70,7 +71,8 @@ export class TXStore{ address, blueScore:utxo.blockDaaScore, tx:false,//TODO - isMoved:true + isMoved:true, + isCoinbase:false }; } this.emitTx(dbItem); @@ -86,6 +88,7 @@ export class TXStore{ amount: utxo.amount, address, blueScore:utxo.blockDaaScore, + isCoinbase:utxo.isCoinbase, tx:false//TODO }; this.add(item); diff --git a/wallet/utxo.ts b/wallet/utxo.ts index 3d140c1..08cff4c 100644 --- a/wallet/utxo.ts +++ b/wallet/utxo.ts @@ -10,6 +10,7 @@ import {EventTargetImpl} from './event-target-impl'; const KAS = helper.KAS; export {UnspentOutput}; export const CONFIRMATION_COUNT = 10; +export const COINBASE_CFM_COUNT = 100; let seq = 0; export class UtxoSet extends EventTargetImpl { @@ -58,7 +59,7 @@ export class UtxoSet extends EventTargetImpl { //console.log("utxoInUse", {utxoInUse, alreadyHaveIt}) if (!utxoInUse && !alreadyHaveIt /*&& utxo.isSpendable*/ ) { utxoIds.push(utxoId); - let confirmed = (blueScore-utxo.blockDaaScore>=CONFIRMATION_COUNT); + let confirmed = (blueScore-utxo.blockDaaScore>= (utxo.isCoinbase? COINBASE_CFM_COUNT : CONFIRMATION_COUNT)); let unspentOutput = new UnspentOutput({ txid: utxo.transactionId, address, @@ -170,7 +171,7 @@ export class UtxoSet extends EventTargetImpl { updateUtxoBalance(): void { const {blueScore} = this.wallet; [...this.utxos.pending.values()].forEach(utxo=>{ - if(blueScore-utxo.blockDaaScore < CONFIRMATION_COUNT) + if(blueScore-utxo.blockDaaScore < (utxo.isCoinbase? COINBASE_CFM_COUNT : CONFIRMATION_COUNT)) return this.utxos.pending.delete(utxo.txId+utxo.outputIndex); this.wallet.adjustBalance(false, -utxo.satoshis, false); diff --git a/wallet/wallet.ts b/wallet/wallet.ts index 9aadb0d..143a0a7 100644 --- a/wallet/wallet.ts +++ b/wallet/wallet.ts @@ -17,7 +17,7 @@ import { import {CreateLogger, Logger} from '../utils/logger'; import {AddressManager} from './address-manager'; -import {UnspentOutput, UtxoSet, CONFIRMATION_COUNT} from './utxo'; +import {UnspentOutput, UtxoSet, CONFIRMATION_COUNT, COINBASE_CFM_COUNT} from './utxo'; import {TXStore} from './tx-store'; import {CacheStore} from './cache-store'; import {KaspaAPI, ApiError} from './api'; @@ -35,7 +35,7 @@ const SompiPerKaspa = 100_000_000 // MaxSompi is the maximum transaction amount allowed in sompi. const MaxSompi = 21_000_000 * SompiPerKaspa -export {kaspacore, COMPOUND_UTXO_MAX_COUNT, CONFIRMATION_COUNT}; +export {kaspacore, COMPOUND_UTXO_MAX_COUNT, CONFIRMATION_COUNT, COINBASE_CFM_COUNT}; /** Class representing an HDWallet with derivable child addresses */ class Wallet extends EventTargetImpl { @@ -1125,7 +1125,8 @@ class Wallet extends EventTargetImpl { in:false, ts, id:txid, amount, address:toAddr, note, blueScore: this.blueScore, tx:rpcTX.transaction, - myAddress: this.addressManager.isOur(toAddr) + myAddress: this.addressManager.isOur(toAddr), + isCoinbase: false }) this.updateDebugInfo(); this.emitCache()