예제 #1
0
 def __init__(self, register_private_key: str):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.account = Account(register_private_key)
     self.cid = self.account.cid()
     self.signature = None
     self.gen_signature()
     self.serialize_data = None
예제 #2
0
 def __init__(self, private_key: str, cr_private_key: str, proposal_type: int, category_data: str,
              draft_hash: bytes, budget=None, recipient=None, target_proposal_hash=None, new_recipient=None,
              secretary_general_private_key=None, new_owner_private_key=None):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.account = Account(private_key)
     self.cr_account = Account(cr_private_key)
     self.secretary_general_account = None
     self.new_owner_account = None
     self.proposal_type = proposal_type
     self.category_data = category_data
     self.draft_hash = draft_hash
     self.target_proposal_hash = target_proposal_hash
     self.new_owner_public_key = None
     self.budget = budget
     self.recipient = recipient
     self.new_recipient = None
     self.secretary_general_public_key = None
     self.secretary_general_did = None
     self.sign = None
     self.new_owner_signature = None
     self.secretary_general_signature = None
     self._gen_secretary_general_account(secretary_general_private_key)
     self._gen_new_owner_account(new_owner_private_key)
     self.cr_council_member_did = bytes.fromhex(self.cr_account.did())
     self.cr_council_member_sign = None
     self._gen_signature()
     self.hash = self.gen_hash()
     self.serialize_data = None
 def __init__(self, private_key: str, proposal_hash: bytes):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.account = Account(private_key)
     self.proposal_hash = proposal_hash
     self.sponsor_public_key = bytes.fromhex(self.account.public_key())
     self.sign = None
     self.gen_signature()
     self.serialize_data = None
예제 #4
0
 def __init__(self, params: dict, program_hash=None, gas=0):
     Payload.__init__(self, Payload.DEFAULT_VERSION)
     self.code_hash = "1c7779c302193ebc1523a7fe627497a31808fede95"
     self.code = None
     self.params = params
     self.program_hash = program_hash
     self.gas = gas
     self.gen_code()
예제 #5
0
 def __init__(self, private_key: str, proposal_hash: bytes, vote_result: int, opinion_hash: bytes):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.account = Account(private_key)
     self.proposal_hash = proposal_hash
     self.vote_result = vote_result
     self.opinion_hash = opinion_hash
     self.did = bytes.fromhex(self.account.did())
     self.sign = None
     self.gen_signature()
     self.serialize_data = None
예제 #6
0
 def __init__(self, owner_account: Account, node_account: Account,
              nickname: str, url: str, location: int, net_address: str):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.owner_account = owner_account
     self.node_account = node_account
     self.nickname = nickname
     self.url = url
     self.location = location
     self.net_address = net_address
     self.signature = self.gen_signature()
예제 #7
0
 def __init__(self, function_code: FunctionCode, name="", code_version="", author="", email="", description="",
              program_hash=None, gas=0):
     Payload.__init__(self, Payload.DEFAULT_VERSION)
     self.function_code = function_code
     self.name = name
     self.code_version = code_version
     self.author = author
     self.email = email
     self.description = description
     self.program_hash = program_hash
     self.gas = gas
 def __init__(self, private_key: str, nickname: str, url: str,
              location: int):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.account = Account(private_key)
     self.nickname = nickname
     self.url = url
     self.location = location
     self.code = self.account.redeem_script()
     self.cid = self.account.cid()
     self.did = self.account.did()
     self.signature = None
     self.gen_signature()
     self.serialize_data = None
예제 #9
0
 def __init__(self, private_key: bytes, owner_public_key: bytes,
              node_public_key: bytes, nickname: str, url: str,
              location: int, net_address: str):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.tag = util.tag_from_path(__file__, self.__class__.__name__)
     self.private_key = private_key
     self.owner_public_key = owner_public_key
     self.node_public_key = node_public_key
     self.nickname = nickname
     self.url = url
     self.location = location
     self.net_address = net_address
     self.signature = self.gen_signature()
def create_transaction(input_private_key: str, output_addresses: list, amount: int, rpc_port: int, side_chain: bool):
    account = Account(input_private_key)
    # check output
    if output_addresses is None or len(output_addresses) == 0:
        Logger.error("Invalid output addresses")
        return None

    # create outputs
    outputs, total_amount = create_normal_outputs(
        output_addresses=output_addresses,
        amount=amount,
        fee=util.TX_FEE,
        output_lock=0
    )

    # create inputs
    inputs, change_outputs = create_normal_inputs(account.address(), total_amount, rpc_port)

    if inputs is None or change_outputs is None:
        Logger.error("Create normal inputs failed")
        return None
    outputs.extend(change_outputs)

    # create program
    programs = list()
    redeem_script = bytes.fromhex(account.redeem_script())
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(
        usage=Attribute.NONCE,
        data=bytes("attributes".encode())
    )
    attributes.append(attribute)

    tx = Transaction()
    if not side_chain :
        tx.version = Transaction.TX_VERSION_09
    else:
        tx.version = Transaction.TX_VERSION_DEFAULT

    tx.tx_type = Transaction.TRANSFER_ASSET
    tx.payload = Payload(Payload.DEFAULT_VERSION)
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    return tx
 def __init__(self, secretary_private_key: str, leader_private_key: str,
              new_leader_private_key, tracking_type: int,
              proposal_hash: bytes, document_hash: bytes, stage: int,
              secretary_opinion_hash: bytes):
     Payload.__init__(self, self.DEFAULT_VERSION)
     self.secretary_general_account = Account(secretary_private_key)
     self.leader_account = Account(leader_private_key)
     self.new_leader_account = None
     self.proposal_hash = proposal_hash
     self.document_hash = document_hash
     self.stage = stage
     self.leader_public_key = bytes.fromhex(
         self.leader_account.public_key())
     self.new_leader_public_key = None
     self.proposal_tracking_type = tracking_type
     self.secretary_opinion_hash = secretary_opinion_hash
     self.secretary_general_sign = None
     self.leader_sign = None
     self.new_leader_sign = None
     self._get_new_leader_account(new_leader_private_key)
     self.gen_signature()
     self.serialize_data = None
def create_vote_transaction(input_private_key: str, candidates_list: list, amount: int, rpc_port: int, vote_content):
    # check output
    if candidates_list is None or len(candidates_list) == 0:
        Logger.error("Invalid output addresses")
        return None

    # candidates_bytes_list = list()
    #
    # for candidate in candidates_list:
    #     candidates_bytes_list.append(bytes.fromhex(candidate))

    # create outputs
    account = Account(input_private_key)
    outputs = create_vote_output(account.address(), amount, vote_content)

    # create inputs
    total_amount = amount + util.TX_FEE
    inputs, change_outputs = create_normal_inputs(account.address(), total_amount, rpc_port)
    if inputs is None or change_outputs is None:
        Logger.error("Create normal inputs failed")
        return None
    outputs.extend(change_outputs)

    # create program
    programs = list()
    redeem_script = bytes.fromhex(account.redeem_script())
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(
        usage=Attribute.NONCE,
        data=bytes("attributes".encode())
    )
    attributes.append(attribute)

    tx = Transaction()
    tx.version = Transaction.TX_VERSION_09
    tx.tx_type = Transaction.TRANSFER_ASSET
    tx.payload = Payload(Payload.DEFAULT_VERSION)
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    return tx
예제 #13
0
def create_transaction(keystore: KeyStore, output_addresses: list, amount: int, fee=10000, output_lock=0):
    # check output
    if output_addresses is None or len(output_addresses) == 0:
        Logger.error("Invalid output addresses")
        return None

    # create outputs
    outputs, total_amount = create_normal_outputs(
        output_addresses=output_addresses,
        amount=amount,
        fee=fee,
        output_lock=output_lock
    )

    # create inputs
    inputs, change_outputs = create_normal_inputs(keystore.address, total_amount)

    if inputs is None or change_outputs is None:
        Logger.error("Create normal inputs failed")
        return None
    outputs.extend(change_outputs)

    # create program
    programs = list()
    redeem_script = keystore.sign_script
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(
        usage=Attribute.NONCE,
        data=bytes("attributes".encode())
    )
    attributes.append(attribute)

    tx = Transaction()
    tx.version = Transaction.TX_VERSION_09
    tx.tx_type = Transaction.TRANSFER_ASSET
    tx.payload = Payload(Payload.DEFAULT_VERSION)
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    return tx
예제 #14
0
def create_redeem_transaction(keystore: KeyStore, amount: int):

    # create outputs
    outputs, total_amount = create_normal_outputs(
        output_addresses=[keystore.address],
        amount=amount,
        fee=10000,
        output_lock=0
    )

    # create inputs

    deposit_address = keytool.gen_deposit_address(keystore.program_hash)
    inputs, change_outputs = create_normal_inputs(deposit_address, total_amount)
    if inputs is None or change_outputs is None:
        Logger.error("Create normal inputs failed")
        return None
    outputs.extend(change_outputs)

    # create program
    programs = list()
    redeem_script = keystore.sign_script
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(
        usage=Attribute.NONCE,
        data=bytes("attributes".encode())
    )
    attributes.append(attribute)

    tx = Transaction()
    tx.version = Transaction.TX_VERSION_09
    tx.tx_type = Transaction.RETURN_DEPOSIT_CHAIN
    tx.payload_version = 0
    tx.payload = Payload(Payload.DEFAULT_VERSION)
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    return tx
def create_cr_redeem_transaction(payload: CRInfo, output_address: str, amount: int, rpc_port: int):
    # create outputs
    outputs, total_amount = create_normal_outputs(
        output_addresses=[output_address],
        amount=amount,
        fee=util.TX_FEE,
        output_lock=0
    )

    # create inputs

    deposit_address = payload.get_deposit_address()
    inputs, change_outputs = create_normal_inputs(deposit_address, total_amount, rpc_port)
    if inputs is None or change_outputs is None:
        Logger.error("Create normal inputs failed")
        return None
    outputs.extend(change_outputs)

    # create program
    programs = list()
    redeem_script = bytes.fromhex(payload.account.redeem_script())
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(
        usage=Attribute.NONCE,
        data=bytes("attributes".encode())
    )
    attributes.append(attribute)

    tx = Transaction()
    tx.version = Transaction.TX_VERSION_09
    tx.tx_type = Transaction.RETURN_CR_DEPOSIT_COIN
    tx.payload_version = 0
    tx.payload = Payload(Payload.DEFAULT_VERSION)
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    return tx
예제 #16
0
 def __init__(self):
     Payload.__init__(self, Payload.DEFAULT_VERSION)
     self.cross_chain_addresses = list()
     self.output_indexes = list()
     self.cross_chain_amounts = list()
예제 #17
0
    programs = list()
    redeem_script = bytes.fromhex(
        "2102d5b81d2f002b1ace56f6da5a35322df75544d71699af31bd30cfbfd348a61e15ac"
    )
    program = Program(code=redeem_script, params=None)
    programs.append(program)

    # create attributes
    attributes = list()
    attribute = Attribute(usage=Attribute.NONCE,
                          data=bytes("attributes".encode()))
    attributes.append(attribute)

    tx = Transaction()
    tx.version = Transaction.TX_VERSION_09
    tx.tx_type = Transaction.TRANSFER_ASSET
    tx.payload = Payload(0)
    tx.attributes = attributes
    tx.inputs = inputs
    tx.outputs = outputs
    tx.lock_time = 0
    tx.programs = programs

    r = tx.serialize()
    r2 = tx.serialize_unsigned()

    print(tx)
    print("transaction serial: ", r.hex())
    print("tx serial unsigned: ", r2.hex())
예제 #18
0
 def __init__(self, pub_key=None, pri_key=None, signature=None):
     Payload.__init__(self, self.PROCESS_PRODUCER_VERSION)
     self.public_key = pub_key
     self.private_key = pri_key
     if pub_key is not None and pri_key is not None:
         self.signature = self.set_signature()