Ejemplo n.º 1
0
def importtest():
    privatekey2 = 'cTeJE6qL8FUP6RGfKiS8Ji61ncMPJzdFtuv9s5TkpYyHbZ8EisSX'
    btccore.changewallet(privatekey2)
    x, y = ardubridge.getpubkey()
    print('x-coord')
    print(x)
    print('y-coord')
    print(y)
    if x == b'69450585114360778982578047439232137453781038709951231527714375955216555119475' and y == b'114780863257592259610368907099699416869271222059464727485966622335048955651600':
        print('import test passed')
        return True
    print('import test failed')
    return False
Ejemplo n.º 2
0
def build_transaction2(transidsarr,
                       transindexarr,
                       pubkeysarr,
                       amountsarr,
                       tnet=True):
    tx_ins = buildinputs(transidsarr, transindexarr)
    print("ins")
    print(tx_ins)
    tx_outs = buildoutputs(pubkeysarr, amountsarr)
    print("pubkeys")
    print(pubkeysarr)
    print("outs")
    print(tx_outs)
    tx_obj = Tx(version=1,
                tx_ins=tx_ins,
                tx_outs=tx_outs,
                locktime=0,
                testnet=tnet)
    #hash_type = SIGHASH_ALL
    #z = tx_obj.sig_hash(0, hash_type)
    #pk = PrivateKey(secret=privatekey)
    for i in range(len(tx_ins)):
        sighash = SIGHASH_ALL
        z = tx_obj.sig_hash(i, sighash)
        #print("getting sign:")
        r, s = ardubridge.sign(z)
        s = int(s)
        others = N - s
        if others < s:
            s = others
        #print("r: " + str(r))
        #print("s: " + str(s))
        sig = Signature(int(r), s)
        der = sig.der()
        sig = der + bytes([sighash])
        #sec = pk.point.sec()
        #print("public point:")
        #print(int(pk.point.x.hex(), 16))
        #print(int(pk.point.y.hex(), 16))
        x, y = ardubridge.getpubkey()
        if (x == -1 and y == -1):
            return '-1'
        #pub = S256Point(53237820045986896539096637357322002537362350769420441605069248472301971758546, 49407176618187043960559197373734381057571970898731550795341045595301080938882)
        pub = S256Point(int(x), int(y))
        sec2 = pub.sec()
        tx_obj.tx_ins[i].script_sig = Script([sig, sec2])
    return hexlify(tx_obj.serialize())
Ejemplo n.º 3
0
def erasetest():
    if not importtest():
        print('could not import')
        return False
    else:
        ardubridge.erase()
        x, y = ardubridge.getpubkey()
        if x != '-1' and y != '-1':
            print('did not erase')
            print('x:')
            print(x)
            print('y:')
            print(y)
            return False
        else:
            print('erase test passed')
            return True
    return False
Ejemplo n.º 4
0
def build_transaction3(pubkey, value, fee):
    #print('f1')
    if type(fee) == type('s'):
        fee = int(fee)
    if type(value) == type('s'):
        value = int(value)
    #print('f2')
    x, y = ardubridge.getpubkey()
    if x == -1 and y == -1:
        return -1
    print('f3')
    nettype = checkaddrtype(pubkey)
    if nettype == 'testnet' or nettype == 'mainnet':
        testnet = True
        if nettype == 'testnet':
            print("testnet destination detected.")
            testnet = True
        elif nettype == 'mainnet':
            print("destination is mainnet")
            testnet = False
        addr = getaddress(int(x.decode("utf-8")), int(y.decode("utf-8")),
                          testnet)
    else:
        print("destination address is not on blockchain. sending junk.")
        return '-1'

    #print(addr)
    #print('f4')
    addrs = addr.decode("UTF-8")
    #print('f5')
    transidsarr, transindexarr, leftover = transactions.grabinputs(
        addrs, value, testnet)
    #print('f6')
    #fee = transactions.get_transaction_fee(transactions.get_transaction_rate(),transactions.get_transaction_size(len(transidsarr),2)) #assumes 2 is the number of outputs
    return build_transaction2(transidsarr, transindexarr, [pubkey, addrs],
                              [value, leftover - fee], testnet)
Ejemplo n.º 5
0
def debug3():
    x, y = ardubridge.getpubkey()
    print(x)
    print(y)
Ejemplo n.º 6
0
def getaddress2(testnet=False, compressed=True):
    x, y = ardubridge.getpubkey()
    if (x == '-1' and y == '-1'):
        return '-1'
    return getaddress(int(x.decode("utf-8")), int(y.decode("utf-8")), testnet,
                      compressed).decode('utf-8')
Ejemplo n.º 7
0
def checkpubkey():
    x, y = ardubridge.getpubkey()
    print('x-coord')
    print(x)
    print('y-coord')
    print(y)