diff --git a/api/types.go b/api/types.go index c283989354..9d7ab6a6fd 100644 --- a/api/types.go +++ b/api/types.go @@ -342,6 +342,8 @@ type Address struct { TotalSentSat *Amount `json:"totalSent,omitempty"` UnconfirmedBalanceSat *Amount `json:"unconfirmedBalance"` UnconfirmedTxs int `json:"unconfirmedTxs"` + UnconfirmedSending *Amount `json:"unconfirmedSending,omitempty"` + UnconfirmedReceiving *Amount `json:"unconfirmedReceiving,omitempty"` Txs int `json:"txs"` AddrTxCount int `json:"addrTxCount,omitempty"` NonTokenTxs int `json:"nonTokenTxs,omitempty"` diff --git a/api/worker.go b/api/worker.go index 799c90e804..8e30bc3680 100644 --- a/api/worker.go +++ b/api/worker.go @@ -1296,6 +1296,8 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco txids []string pg Paging uBalSat big.Int + uBalSending big.Int + uBalReceiving big.Int totalReceived, totalSent *big.Int unconfirmedTxs int totalResults int @@ -1347,12 +1349,12 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco // skip already confirmed txs, mempool may be out of sync if tx.Confirmations == 0 { unconfirmedTxs++ - uBalSat.Add(&uBalSat, tx.getAddrVoutValue(addrDesc)) + uBalReceiving.Add(&uBalReceiving, tx.getAddrVoutValue(addrDesc)) // ethereum has a different logic - value not in input and add maximum possible fees if w.chainType == bchain.ChainEthereumType { - uBalSat.Sub(&uBalSat, tx.getAddrEthereumTypeMempoolInputValue(addrDesc)) + uBalSending.Add(&uBalSending, tx.getAddrEthereumTypeMempoolInputValue(addrDesc)) } else { - uBalSat.Sub(&uBalSat, tx.getAddrVinValue(addrDesc)) + uBalSending.Add(&uBalSending, tx.getAddrVinValue(addrDesc)) } if page == 0 { if option == AccountDetailsTxidHistory { @@ -1419,6 +1421,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco totalSecondaryValue = secondaryRate * totalBaseValue } } + uBalSat.Sub(&uBalReceiving, &uBalSending) r := &Address{ Paging: pg, AddrStr: address, @@ -1430,6 +1433,8 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco InternalTxs: ed.internalTxs, UnconfirmedBalanceSat: (*Amount)(&uBalSat), UnconfirmedTxs: unconfirmedTxs, + UnconfirmedSending: amountOrNil(&uBalSending), + UnconfirmedReceiving: amountOrNil(&uBalReceiving), Transactions: txs, Txids: txids, Tokens: ed.tokens, @@ -1451,6 +1456,14 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco return r, nil } +// Returns either the Amount or nil if the number is zero +func amountOrNil(num *big.Int) *Amount { + if num.Cmp(big.NewInt(0)) == 0 { + return nil + } + return (*Amount)(num) +} + func (w *Worker) balanceHistoryHeightsFromTo(fromTimestamp, toTimestamp int64) (uint32, uint32, uint32, uint32) { fromUnix := uint32(0) toUnix := maxUint32 diff --git a/blockbook-api.ts b/blockbook-api.ts index ca722a371d..279138a118 100644 --- a/blockbook-api.ts +++ b/blockbook-api.ts @@ -159,6 +159,8 @@ export interface Address { totalSent?: string; unconfirmedBalance: string; unconfirmedTxs: number; + unconfirmedSending?: string; + unconfirmedReceiving?: string; txs: number; addrTxCount?: number; nonTokenTxs?: number;