def __getSearchResult(c): txOuts = [] for tmp in c.fetchall(): txOut = TransactionOut(tmp[1], tmp[2], tmp[5], tmp[9], tmp[10], tmp[0], tmp[4], tmp[6]) txOuts.append(txOut) return txOuts
def createNormalCFTransaction(pre_out_ids, pre_cf_hash, spendValue, otherPublicAddrToValueDict, refund_addr): tx_ins = __get_tx_ins(pre_out_ids) pre_cf = TransactionDao.searchByHash(pre_cf_hash) cf_header = pre_cf.cf_header cf_header.lack_amount = cf_header.lack_amount - spendValue cf_header.pre_hash = pre_cf_hash if cf_header.original_hash == '' or cf_header.original_hash == Constants.ZERO_HASH: cf_header.original_hash = pre_cf_hash # cfscript = b'' if cf_header.lack_amount <= 0: #CF suceess outValue = cf_header.target_amount cfscript = standard_tx_out_script(cf_header.pubkey) # elif cf_header.lack_amount == cf_header.target_amount:#CF start # outValue = 0 # cfscript = ScriptPayToAddress(refund_addr).script() else: #CF ing outValue = spendValue cfscript = standard_tx_out_script(refund_addr) #outValue = cf_header.target_amount if cf_header.lack_amount == 0 else spendValue cfout = TransactionOut(outValue, cfscript, 0, 0, cf_header.end_time) tx_outs = __get_tx_outs(otherPublicAddrToValueDict) tx_outs.insert(0, cfout) cf = TransactionCF(cf_header, Constants.VERSION, tx_ins, tx_outs, Constants.LOCK_TIME, None, 0) if verify(cf): insert(cf) return cf
def createFirstCFTransaction(target_amount, pubkey_addr, end_time, pre_out_ids_for_fee=[], cert=''): if len(pre_out_ids_for_fee) == 0: tx_in = TransactionIn.coinbase_tx_in() tx_ins = [] tx_ins.append(tx_in) else: tx_ins = __get_tx_ins(pre_out_ids_for_fee) cert = SecretKeyDao.searchCertByPubAddr(pubkey_addr) cfscript = standard_tx_out_script(pubkey_addr) cfout = TransactionOut(0, cfscript, 0, 0, end_time) tx_outs = [] tx_outs.append(cfout) original_hash = Constants.ZERO_HASH pre_hash = Constants.ZERO_HASH lack_amount = target_amount cf_header = CFHeader(original_hash, target_amount, pubkey_addr, end_time, pre_hash, lack_amount, cert) cf = TransactionCF(cf_header, Constants.VERSION, tx_ins, tx_outs, Constants.LOCK_TIME) if verify(cf): insert(cf) return cf
def __getSearchResultSingle(c): tmp = c.fetchone() if tmp == None: return None else: txOut = TransactionOut(tmp[1], tmp[2], tmp[5], tmp[9], tmp[10], tmp[0], tmp[4], tmp[6]) return txOut
def __get_tx_outs(publicAddrToValueArray): tx_outs = [] for singlePublicAddrToValueArray in publicAddrToValueArray: if len(singlePublicAddrToValueArray) == 2: value = singlePublicAddrToValueArray[1] script = standard_tx_out_script(singlePublicAddrToValueArray[0]) tx_out = TransactionOut(value, script, 0, 0) tx_outs.append(tx_out) return tx_outs