Esempio n. 1
0
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 len(tx_ins) != 0:
        cf = signTx(cf, pre_out_ids_for_fee)
        cf.check()
    if verify(cf):
        insert(cf)
        return cf
Esempio n. 2
0
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 len(tx_ins) != 0:
        cf = signTx(cf, pre_out_ids)
        cf.check()
    if verify(cf):
        insert(cf)
        return cf