Ejemplo n.º 1
0
def save(txOut, tx, index):
    deleteOld(tx, index)
    pubicAddress = txOut.address()
    end_time = 0
    if TransactionUtils.isCFTransation(tx):
        if 0 == index:
            end_time = tx.cf_header.end_time
    CoinSqlite3().exec_sql(
        'INSERT INTO TransactionInfoOut(coin_value, script, parentBlockId, parentTxId, state, `index`, pubicAddress, isToMe, usedState, end_time, isMyTx) VALUES (?,?,?,?,?,?,?,?,?,?,?)',
        txOut.coin_value, txOut.script, tx.getBlockHash(), tx.hash(),
        txOut.state, index, pubicAddress,
        SecretKeyDao.isMypubicAddress(pubicAddress), 0, end_time,
        SecretKeyDao.isMypubicAddress(txOut.address()))
Ejemplo n.º 2
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 verify(cf):
        insert(cf)
        return cf
Ejemplo n.º 3
0
def signTx(tx, pre_out_ids=[]):
    pubkey_addr = ''
    outscript = r''
    for pre_out_id in pre_out_ids:
        if '' != pre_out_id:
            pre_out = TransactionOutDao.searchById(pre_out_id)
            pubkey_addr = pre_out.address()
            outscript = pre_out.script
    if '' != pubkey_addr:
        secretKey = SecretKeyDao.searchByPubAddr(pubkey_addr)
        key = Key(
            public_pair=[int(secretKey.publicKey),
                         int(secretKey.privateKey)])
        tx.sign({
            script_obj_from_script(outscript).hash160:
            [secretKey.sec_num, key.public_pair(), True],
        })
    return tx
Ejemplo n.º 4
0
def get_keys():
    secretKeys = SecretKeyDao.searchMySecrets()
    keys = []
    for secretKey in secretKeys:
        keys.append(Key(secretKey))
    return keys
Ejemplo n.º 5
0
def manageKey(secretNum):
    secretKey = SecretKey.create(secretNum)
    SecretKeyDao.save(secretKey)
    print(secretKey)