bitcoin/BRWallet.c
// adds a transaction to the wallet, or returns false if it isn't associated with the wallet
adds a transaction to the wallet, or returns false if it isn't associated with the wallet
adds a transaction to the wallet or returns false if it isn ' t associated with the wallet
int BRWalletRegisterTransaction(BRWallet *wallet, BRTransaction *tx)
{
    int wasAdded = 0, r = 1;
    assert(wallet != NULL);
    assert(tx != NULL && BRTransactionIsSigned(tx));
    if (tx && BRTransactionIsSigned(tx)) {
        pthread_mutex_lock(&wallet->lock);
        if (! BRSetContains(wallet->allTx, tx)) {
            if (_BRWalletContainsTx(wallet, tx)) {
                BRSetAdd(wallet->allTx, tx);
                _BRWalletInsertTx(wallet, tx);
                _BRWalletUpdateBalance(wallet);
                wasAdded = 1;
            }
            else { 
                if (tx->blockHeight == TX_UNCONFIRMED) BRSetAdd(wallet->allTx, tx);
                r = 0;
            }
        }
        pthread_mutex_unlock(&wallet->lock);
    }
    else r = 0;
    if (wasAdded) {
        BRWalletUnusedAddrs(wallet, NULL, SEQUENCE_GAP_LIMIT_EXTERNAL, SEQUENCE_EXTERNAL_CHAIN);
        BRWalletUnusedAddrs(wallet, NULL, SEQUENCE_GAP_LIMIT_INTERNAL, SEQUENCE_INTERNAL_CHAIN);
        if (wallet->balanceChanged) wallet->balanceChanged(wallet->callbackInfo, wallet->balance);
        if (wallet->txAdded) wallet->txAdded(wallet->callbackInfo, tx);
    }
    return r;
}
int BRWalletRegisterTransaction ( BRWallet * wallet , BRTransaction * tx ) { int wasAdded = 0 , r = 1 ; assert ( wallet != NULL ) ; assert ( tx != NULL && BRTransactionIsSigned ( tx ) ) ; if ( tx && BRTransactionIsSigned ( tx ) ) { pthread_mutex_lock ( & wallet -> lock ) ; if ( ! BRSetContains ( wallet -> allTx , tx ) ) { if ( _BRWalletContainsTx ( wallet , tx ) ) { BRSetAdd ( wallet -> allTx , tx ) ; _BRWalletInsertTx ( wallet , tx ) ; _BRWalletUpdateBalance ( wallet ) ; wasAdded = 1 ; } else { if ( tx -> blockHeight == TX_UNCONFIRMED ) BRSetAdd ( wallet -> allTx , tx ) ; r = 0 ; } } pthread_mutex_unlock ( & wallet -> lock ) ; } else r = 0 ; if ( wasAdded ) { BRWalletUnusedAddrs ( wallet , NULL , SEQUENCE_GAP_LIMIT_EXTERNAL , SEQUENCE_EXTERNAL_CHAIN ) ; BRWalletUnusedAddrs ( wallet , NULL , SEQUENCE_GAP_LIMIT_INTERNAL , SEQUENCE_INTERNAL_CHAIN ) ; if ( wallet -> balanceChanged ) wallet -> balanceChanged ( wallet -> callbackInfo , wallet -> balance ) ; if ( wallet -> txAdded ) wallet -> txAdded ( wallet -> callbackInfo , tx ) ; } return r ; }
adds a transaction to the wallet, or returns false if it isn't associated with the wallet
adds a transaction to the wallet or returns false if it isn ' t associated with the wallet
// TODO: verify signatures when possible // TODO: handle tx replacement with input sequence numbers //       (for now, replacements appear invalid until confirmation) // keep track of unconfirmed non-wallet tx for invalid tx checks and child-pays-for-parent fees // BUG: limit total non-wallet unconfirmed tx to avoid memory exhaustion attack // BUG: XXX memory leak if tx is not added to wallet->allTx, and we can't just free it // when a wallet address is used in a transaction, generate a new address to replace it