Example #1
0
def create_intkey_transaction(verb, name, value, private_key, public_key):
    payload = IntKeyPayload(verb=verb, name=name, value=value)

    # The prefix should eventually be looked up from the
    # validator's namespace registry.
    intkey_prefix = hashlib.sha512('intkey'.encode('utf-8')).hexdigest()[0:6]

    addr = intkey_prefix + hashlib.sha512(name.encode('utf-8')).hexdigest()

    header = transaction_pb2.TransactionHeader(
        signer_pubkey=public_key,
        family_name='intkey',
        family_version='1.0',
        inputs=[addr],
        outputs=[addr],
        dependencies=[],
        payload_encoding="application/cbor",
        payload_sha512=payload.sha512(),
        batcher_pubkey=public_key,
        nonce=time.time().hex().encode())

    header_bytes = header.SerializeToString()

    signature = bitcoin.ecdsa_sign(header_bytes, private_key)

    transaction = transaction_pb2.Transaction(header=header_bytes,
                                              payload=payload.to_cbor(),
                                              header_signature=signature)

    return transaction
Example #2
0
def create_jvm_sc_transaction(verb,
                              private_key,
                              public_key,
                              bytecode=None,
                              methods=None,
                              byte_addr=None,
                              method=None,
                              parameters=None,
                              addresses=None):

    payload = JVM_SC_Payload(verb=verb,
                             bytecode=bytecode,
                             methods=methods,
                             byte_addr=byte_addr,
                             method=method,
                             parameters=parameters)

    if addresses is None:
        addresses = []

    # The prefix should eventually be looked up from the
    # validator's namespace registry.
    if byte_addr is not None:
        addr = byte_addr
    elif bytecode is not None:
        addr = get_address('jvm_sc', bytecode)
    else:
        raise Exception

    addresses.append(addr)
    header = transaction_pb2.TransactionHeader(
        signer=public_key,
        family_name='jvm_sc',
        family_version='1.0',
        inputs=addresses,
        outputs=addresses,
        dependencies=[],
        payload_encoding="application/protobuf",
        payload_sha512=payload.sha512(),
        batcher=public_key)
    header_bytes = header.SerializeToString()

    signature = pybitcointools.ecdsa_sign(header_bytes, private_key)

    transaction = transaction_pb2.Transaction(header=header_bytes,
                                              payload=payload.payload_bytes,
                                              signature=signature)

    return transaction