Beispiel #1
0
def extractAddrValue(op: TealOp) -> Union[str, bytes]:
    """Extract the constant value being loaded by a TealOp whose op is Op.addr.
    
    Returns:
        If the op is loading a template variable, returns the name of the variable as a string.
        Otherwise, returns the bytes of the public key of the address that the op is loading.
    """
    if len(op.args) != 1 or type(op.args[0]) != str:
        raise TealInternalError("Unexpected args in addr opcode: {}".format(
            op.args))

    value = cast(str, op.args[0])
    if not value.startswith('TMPL_'):
        value = encoding.decode_address(value)
    return value
Beispiel #2
0
def create_smart_contract_endpoint():
    data = request.get_json()
    if data is None:
        return '', 400
    msg = None
    if 'passphrase' not in data:
        msg = 'Passphrase missing'
    elif 'assetId' not in data:
        msg = 'Asset ID missing'
    elif 'amount' not in data:
        msg = 'Amount missing'
    elif 'start' not in data or 'end' not in data:
        msg = 'Start or end time missing'
    elif 'minBid' not in data:
        msg = 'Minimum bid missing'
    if msg is not None:
        return jsonify(message=msg), 400

    approval_program, clear_program = compile_smart_contract(algod_client)

    sender_account = get_wallet_key_pairs(ESCROW_MNEMONIC)
    state_schema = {
        'gint': 7, 'gbyte': 3,
        'lint': 1, 'lbyte': 0
    }
    args = [
        data['assetId'].to_bytes(8, 'big'),
        data['start'].to_bytes(8, 'big'),
        data['end'].to_bytes(8, 'big'),
        int(data['minBid'] * 10 ** 6).to_bytes(8, 'big'),
        data['amount'].to_bytes(8, 'big'),
        encoding.decode_address(get_wallet_key_pairs(data['passphrase'])['public_key'])
    ]

    txn = create_contract_transaction(algod_client, sender_account, approval_program, clear_program, state_schema, args)
    if not txn['status']:
        return jsonify(message=txn['info']), 500
    del txn['status']
    # check if correct values are stored in the contract's global state
    read_global_state(algod_client, sender_account['public_key'], txn['contract_id'])

    return jsonify(txn), 201
Beispiel #3
0
def decode_addr(context):
    context.pk = encoding.decode_address(context.pk)
Beispiel #4
0
wallet_pwd = sys.argv[6]

kmd = kmd.KMDClient(kmd_token, kmd_address)
wallet = wallet.Wallet(wallet_name, wallet_pwd, kmd)
client = algod.AlgodClient(algod_token, algod_address)

# define creator
creator = sys.argv[7]
creator_private_key = wallet.export_key(creator)

# define escrow as creator first
escrow = sys.argv[7]
game = sys.argv[13]
app_args = sys.argv[8].split(",")

li = [encoding.decode_address(game), encoding.decode_address(escrow)]
for i in app_args:
	li.append(int(i).to_bytes(8, 'big'))

app_args = li

# declare application state storage (immutable)
local_ints = 2
local_bytes = 0
global_ints = 15
global_bytes = 4

# define schema
global_schema = transaction.StateSchema(global_ints, global_bytes)
local_schema = transaction.StateSchema(local_ints, local_bytes)
Beispiel #5
0
 def test_encode_decode(self):
     sk, pk = account.generate_account()
     self.assertEqual(pk,
                      encoding.encode_address(encoding.decode_address(pk)))
     self.assertEqual(pk, account.address_from_private_key(sk))