void addTransaction ( Transaction t , boolean runSanityChecks ) { unCacheTransactions ( ) ; if ( transactions == null ) { transactions = new ArrayList <> ( ) ; } t . setParent ( this ) ; if ( runSanityChecks && transactions . size ( ) == 0 && ! t . isCoinBase ( ) ) throw new RuntimeException ( "Attempted to add a non-coinbase transaction as the first transaction: " + t ) ; else if ( runSanityChecks && transactions . size ( ) > 0 && t . isCoinBase ( ) ) throw new RuntimeException ( "Attempted to add a coinbase transaction when there already is one: " + t ) ; transactions . add ( t ) ; adjustLength ( transactions . size ( ) , t . length ) ; // Force a recalculation next time the values are needed. merkleRoot = null ; hash = null ; }
Adds a transaction to this block with or without checking the sanity of doing so