Beispiel #1
0
def __command_vetting__(state, bindings, pargs) :
    """controller command to interact with an vetting contract
    """

    parser = argparse.ArgumentParser(prog='vetting')
    parser.add_argument('-e', '--enclave', help='URL of the enclave service to use', type=str)
    parser.add_argument('-f', '--save_file', help='File where contract data is stored', type=str)
    parser.add_argument('-q', '--quiet', help='Suppress printing the result', action='store_true')
    parser.add_argument('-w', '--wait', help='Wait for the transaction to commit', action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_verifying_key')
    subparser.add_argument('-s', '--symbol', help='binding symbol for result', type=str)

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument('-t', '--type_id', help='contract identifier for the issuer asset type', type=str, required=True)

    subparser = subparsers.add_parser('approve')
    subparser.add_argument('-i', '--issuer', help='identity of the issuer; ECDSA key', type=str, required=True)

    subparser = subparsers.add_parser('get_authority')
    subparser.add_argument('-i', '--issuer', help='identity of the issuer; ECDSA key', type=str, required=True)
    subparser.add_argument('-s', '--symbol', help='binding symbol for result', type=str)

    options = parser.parse_args(pargs)

    extraparams={'quiet' : options.quiet, 'wait' : options.wait}

    # -------------------------------------------------------
    if options.command == 'get_verifying_key' :
        extraparams['commit'] = False
        message = invocation_request('get-verifying-key')
        result = send_to_contract(state, options.save_file, message, eservice_url=options.enclave, **extraparams)
        if options.symbol :
            bindings.bind(options.symbol, result)
        return


    # -------------------------------------------------------
    if options.command == 'initialize' :
        message = invocation_request('initialize', options.type_id)
        send_to_contract(state, options.save_file, message, eservice_url=options.enclave, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'approve' :
        message = invocation_request('add-approved-key', options.issuer)
        send_to_contract(state, options.save_file, message, eservice_url=options.enclave, **extraparams)
        return

   # -------------------------------------------------------
    if options.command == 'get_authority' :
        extraparams['commit'] = False
        message = invocation_request('get-authority', options.issuer)
        result = send_to_contract(state, options.save_file, message, eservice_url=options.enclave, **extraparams)
        if options.symbol :
            bindings.bind(options.symbol, result)
        return
Beispiel #2
0
def __command_exchange__(state, bindings, pargs):
    """controller command to interact with an exchange contract
    """

    parser = argparse.ArgumentParser(prog='exchange')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save_file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_verifying_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('get_offered_asset')
    subparser = subparsers.add_parser('get_requested_asset')

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument(
        '-r',
        '--root',
        help='key for the root authority for requested issuer',
        type=str,
        required=True)
    subparser.add_argument(
        '-t',
        '--type_id',
        help='contract identifier for the requested asset type',
        type=str,
        required=True)
    subparser.add_argument('-o',
                           '--owner',
                           help='identity of the asset owner; ECDSA key',
                           type=str,
                           default="")
    subparser.add_argument('-c',
                           '--count',
                           help='amount requested',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('offer')
    subparser.add_argument('-a',
                           '--asset',
                           help='serialized escrowed asset',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('claim_offer')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('exchange')
    subparser.add_argument('-a',
                           '--asset',
                           help='serialized escrowed asset',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('claim_exchange')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('cancel')
    subparser = subparsers.add_parser('cancel_attestation')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    # -------------------------------------------------------
    if options.command == 'get_verifying_key':
        extraparams['commit'] = False
        message = "'(get-verifying-key)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'get_offered_asset':
        extraparams['commit'] = False
        message = "'(examine-offered-asset)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'get_requested_asset':
        extraparams['commit'] = False
        message = "'(examine-requested-asset)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'initialize':
        asset_request = "(\"{0}\" {1} \"{2}\")".format(options.type_id,
                                                       options.count,
                                                       options.owner)
        message = "'(initialize {0} \"{1}\")".format(asset_request,
                                                     options.root)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'offer':
        message = "'(offer-asset {0})".format(options.asset)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'claim_offer':
        extraparams['commit'] = False
        message = "'(claim-offer)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'exchange':
        message = "'(exchange-asset {0})".format(options.asset)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'claim_exchange':
        extraparams['commit'] = False
        message = "'(claim-exchange)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'cancel':
        message = "'(cancel)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'cancel_attestation':
        extraparams['commit'] = False
        message = "'(cancel-attestation)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return
Beispiel #3
0
def __command_asset_type__(state, bindings, pargs):
    """controller command to interact with an asset_type contract
    """

    parser = argparse.ArgumentParser(prog='asset_type')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save_file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument('-d',
                           '--description',
                           help='human readable description',
                           type=str,
                           default='')
    subparser.add_argument('-n',
                           '--name',
                           help='human readable name',
                           type=str,
                           default='')
    subparser.add_argument('-l',
                           '--link',
                           help='URL where more information is located',
                           type=str,
                           default='')

    subparser = subparsers.add_parser('get_identifier')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('get_description')
    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    # -------------------------------------------------------
    if options.command == 'initialize':
        message = "'(initialize \"{0}\" \"{1}\" \"{2}\")".format(
            options.name, options.description, options.link)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'get_identifier':
        extraparams['commit'] = False
        message = "'(get-identifier)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'get_description':
        extraparams['quiet'] = True
        extraparams['commit'] = False
        message = "'(get-name)"
        name = send_to_contract(state, options.save_file, options.enclave,
                                message, **extraparams)
        message = "'(get-description)"
        description = send_to_contract(state, options.save_file,
                                       options.enclave, message, **extraparams)
        message = "'(get-link)"
        link = send_to_contract(state, options.save_file, options.enclave,
                                message, **extraparams)
        print("NAME: {0}".format(name))
        print("DESC: {1}".format(description))
        print("LINK: {2}".format(link))

        return
Beispiel #4
0
def __command_auction__(state, bindings, pargs):
    """controller command to interact with an auction contract
    """

    parser = argparse.ArgumentParser(prog='auction')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save-file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_signing_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument('-k',
                           '--key',
                           help='public key of the asset contract',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('prime')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Escrow attestation from the asset ledger',
                           type=invocation_parameter,
                           required=True)

    subparser = subparsers.add_parser('submit_bid')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Escrow attestation from the asset ledger',
                           type=invocation_parameter,
                           required=True)

    subparser = subparsers.add_parser('get_offered_asset')
    subparser = subparsers.add_parser('cancel_bid')
    subparser = subparsers.add_parser('check_bid')

    subparser = subparsers.add_parser('max_bid')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('close_bidding')

    subparser = subparsers.add_parser('exchange_attestation')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('cancel_attestation')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    if options.command == 'get_signing_key':
        message = invocation_request('get-public-signing-key')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'initialize':
        message = invocation_request('initialize', options.key)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'prime':
        assert type(options.attestation) is list
        assert len(options.attestation) == 3

        bidinfo = options.attestation[0]
        dependencies = options.attestation[1]
        signature = options.attestation[2]
        message = invocation_request('prime-auction*', bidinfo, dependencies,
                                     signature)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'submit_bid':
        assert type(options.attestation) is list
        assert len(options.attestation) == 3

        bidinfo = options.attestation[0]
        dependencies = options.attestation[1]
        signature = options.attestation[2]
        message = invocation_request('submit-bid*', bidinfo, dependencies,
                                     signature)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'get_offered_asset':
        message = invocation_request('get-offered-asset')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'cancel_bid':
        message = invocation_request('cancel-bid')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'check_bid':
        message = invocation_request('check-bid')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'max_bid':
        message = invocation_request('max-bid')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'close_bidding':
        message = invocation_request('close-bidding')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'cancel_attestation':
        message = invocation_request('cancel-attestation')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if options.symbol:
            bindings.bind(options.symbol, json.dumps(result))
        return

    if options.command == 'exchange_attestation':
        message = invocation_request('exchange-attestation')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if options.symbol:
            bindings.bind(options.symbol, json.dumps(result))
        return
Beispiel #5
0
def __command_auction__(state, bindings, pargs):
    """controller command to interact with an auction contract
    """

    parser = argparse.ArgumentParser(prog='auction')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save-file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_signing_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument('-k',
                           '--key',
                           help='public key of the asset contract',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('prime')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Escrow attestation from the asset ledger',
                           type=str,
                           required=True)
    #subparser.add_argument('-b', '--bidinfo', help='information about the asset to auction', type=str, required=True)
    #subparser.add_argument('-d', '--dependencies', help='proof of escrow dependencies', type=str, nargs='*', default=[])
    #subparser.add_argument('-s', '--signature', help='signature from the asset contract', type=str, required=True)

    subparser = subparsers.add_parser('submit_bid')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Escrow attestation from the asset ledger',
                           type=str,
                           required=True)
    #subparser.add_argument('-b', '--bidinfo', help='information about the asset to auction', type=str, required=True)
    #subparser.add_argument('-d', '--dependencies', help='proof of escrow dependencies', type=str, nargs='*', default=[])
    #subparser.add_argument('-s', '--signature', help='signature from the asset contract', type=str, required=True)

    subparser = subparsers.add_parser('get_offered_asset')
    subparser = subparsers.add_parser('cancel_bid')
    subparser = subparsers.add_parser('check_bid')
    subparser = subparsers.add_parser('max_bid')
    subparser = subparsers.add_parser('close_bidding')

    subparser = subparsers.add_parser('exchange_attestation')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('cancel_attestation')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    if options.command == 'get_signing_key':
        message = "'(get-public-signing-key)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'initialize':
        message = "'(initialize \"{0}\")".format(options.key)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'prime':
        attestation = SchemeExpression.ParseExpression(options.attestation)
        bidinfo = str(attestation.nth(0))
        dependencies = str(attestation.nth(1))
        signature = str(attestation.nth(2))
        message = "'(prime-auction* {0} {1} {2})".format(
            bidinfo, dependencies, signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'submit_bid':
        attestation = SchemeExpression.ParseExpression(options.attestation)
        bidinfo = str(attestation.nth(0))
        dependencies = str(attestation.nth(1))
        signature = str(attestation.nth(2))
        message = "'(submit-bid* {0} {1} {2})".format(bidinfo, dependencies,
                                                      signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'get_offered_asset':
        message = "'(get-offered-asset)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'cancel_bid':
        message = "'(cancel-bid)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'check_bid':
        message = "'(check-bid)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'max_bid':
        message = "'(max-bid)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'close_bidding':
        message = "'(close-bidding)"
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'cancel_attestation':
        message = "'(cancel-attestation)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'exchange_attestation':
        message = "'(exchange-attestation)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return
def __command_kv__(state, bindings, pargs) :
    """controller command to interact with an asset_type contract
    """

    parser = argparse.ArgumentParser(prog='attestation-test')
    parser.add_argument('-e', '--enclave', help='URL of the enclave service to use', type=str, default='preferred')
    parser.add_argument('-f', '--save_file', help='File where contract data is stored', type=str)
    parser.add_argument('-q', '--quiet', help='Suppress printing the result', action='store_true')
    parser.add_argument('-w', '--wait', help='Wait for the transaction to commit', action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get')
    subparser.add_argument('-k', '--key', help='transfer key', type=str, default='_transfer_')
    subparser.add_argument('-s', '--symbol', help='binding symbol for result', type=str)

    subparser = subparsers.add_parser('set')
    subparser.add_argument('-k', '--key', help='transfer key', type=str, default='_transfer_')
    subparser.add_argument('-v', '--value', help='value to send', type=str, required=True)

    options = parser.parse_args(pargs)

    extraparams={'quiet' : options.quiet, 'wait' : options.wait}

    # -------------------------------------------------------
    if options.command == 'get' :

        kv = KeyValueStore()
        with kv :
            kv.set(options.key, "")

        # push the blocks to the eservice so the server can open the store
        eservice_client = __get_eservice_client__(state, options.save_file, options.enclave)
        kv.sync_to_block_store(eservice_client)

        params = {}
        params['encryption_key'] = kv.encryption_key
        params['state_hash'] = kv.hash_identity
        params['transfer_key'] = options.key
        message = invocation_request('kv_get', **params)
        result = send_to_contract(state, options.save_file, message, eservice_url=options.enclave, **extraparams)
        result = json.loads(result)

        # sync the server blocks get to the local block manager
        count = kv.sync_from_block_store(result, eservice_client)
        logger.debug("sync complete with %d blocks", count)

        with kv :
            value = kv.get(options.key)
            logger.debug("value: %s", value)

        if options.symbol :
            bindings.bind(options.symbol, value)

        return value

    # -------------------------------------------------------
    if options.command == 'set' :

        kv = KeyValueStore()
        with kv :
            kv.set(options.key, options.value)

        # push the blocks to the eservice so the server can open the store
        # local_block_store = pblocks.local_block_manager()
        eservice_client = __get_eservice_client__(state, options.save_file, options.enclave)
        kv.sync_to_block_store(eservice_client)

        params = {}
        params['encryption_key'] = kv.encryption_key
        params['state_hash'] = kv.hash_identity
        params['transfer_key'] = options.key
        message = invocation_request('kv_set', **params)
        send_to_contract(state, options.save_file, message, eservice_url=options.enclave, **extraparams)

        return
def __command_integer_key__(state, bindings, pargs):
    """controller command to interact with an integer-key contract
    """

    parser = argparse.ArgumentParser(prog='integer_key')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save-file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    create_parser = subparsers.add_parser('create')
    create_parser.add_argument('-k',
                               '--key',
                               help='key to create',
                               type=str,
                               required=True)
    create_parser.add_argument('-v',
                               '--value',
                               help='initial value to give to the key',
                               type=int,
                               default=0)

    inc_parser = subparsers.add_parser('inc')
    inc_parser.add_argument('-k',
                            '--key',
                            help='key to increment',
                            type=str,
                            required=True)
    inc_parser.add_argument('-v',
                            '--value',
                            help='initial value to give to the key',
                            type=int,
                            required=True)

    dec_parser = subparsers.add_parser('dec')
    dec_parser.add_argument('-k',
                            '--key',
                            help='key to decrement',
                            type=str,
                            required=True)
    dec_parser.add_argument('-v',
                            '--value',
                            help='initial value to give to the key',
                            type=int,
                            required=True)

    get_parser = subparsers.add_parser('get')
    get_parser.add_argument('-k',
                            '--key',
                            help='key to retrieve',
                            type=str,
                            required=True)

    transfer_parser = subparsers.add_parser('transfer')
    transfer_parser.add_argument('-k',
                                 '--key',
                                 help='key to transfer',
                                 type=str,
                                 required=True)
    transfer_parser.add_argument('-o',
                                 '--owner',
                                 help='identity to transfer ownership',
                                 type=str,
                                 required=True)

    escrow_parser = subparsers.add_parser('escrow')
    escrow_parser.add_argument('-k',
                               '--key',
                               help='key to escrow',
                               type=str,
                               required=True)
    escrow_parser.add_argument('-a',
                               '--agent',
                               help='identity of the escrow agent',
                               type=str,
                               required=True)

    attestation_parser = subparsers.add_parser('attestation')
    attestation_parser.add_argument('-k',
                                    '--key',
                                    help='key to escrow',
                                    type=str,
                                    required=True)
    attestation_parser.add_argument('-s',
                                    '--symbol',
                                    help='binding symbol for result',
                                    type=str,
                                    nargs=3)

    disburse_parser = subparsers.add_parser('disburse')
    disburse_parser.add_argument('-d',
                                 '--dependencies',
                                 help='list of dependencies',
                                 type=str,
                                 nargs='*',
                                 default=[])
    disburse_parser.add_argument('-k',
                                 '--key',
                                 help='key to disburse',
                                 type=str,
                                 required=True)
    disburse_parser.add_argument('-s',
                                 '--signature',
                                 help='signature from the escrow agent',
                                 type=str,
                                 required=True)

    exchange_parser = subparsers.add_parser('exchange')
    exchange_parser.add_argument('-d',
                                 '--dependencies',
                                 help='list of dependencies',
                                 type=str,
                                 nargs='*',
                                 default=[])
    exchange_parser.add_argument('--key1',
                                 help='source key',
                                 type=str,
                                 required=True)
    exchange_parser.add_argument('--key2',
                                 help='destination key',
                                 type=str,
                                 required=True)
    exchange_parser.add_argument('-s',
                                 '--signature',
                                 help='signature from the escrow agent',
                                 type=str,
                                 required=True)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    if options.command == 'create':
        message = "'(create \"{0}\" {1})".format(options.key, options.value)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'inc':
        message = "'(inc \"{0}\" {1})".format(options.key, options.value)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'dec':
        message = "'(dec \"{0}\" {1})".format(options.key, options.value)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'get':
        extraparams['commit'] = False
        message = "'(get-value \"{0}\")".format(options.key)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'transfer':
        message = "'(transfer-ownership \"{0}\" \"{1}\")".format(
            options.key, options.owner)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'escrow':
        message = "'(escrow \"{0}\" \"{1}\")".format(options.key,
                                                     options.agent)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'attestation':
        message = "'(escrow-attestation \"{0}\")".format(options.key)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            expression = SchemeExpression.ParseExpression(result)
            bindings.bind(options.symbol[0], str(expression.nth(0)))
            bindings.bind(options.symbol[1], str(expression.nth(1)))
            bindings.bind(options.symbol[2], str(expression.nth(2)))
        return

    if options.command == 'disburse':
        dependencies = " ".join(options.dependencies)
        message = "'(disburse \"{0}\" ({1}) \"{2}\")".format(
            options.key, dependencies, options.signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'exchange':
        dependencies = " ".join(options.dependencies)
        message = "'(disburse \"{0}\" \"{1}\" ({2}) \"{3}\")".format(
            options.key1, options.key2, dependencies, options.signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return
def __command_attestation__(state, bindings, pargs):
    """controller command to interact with an asset_type contract
    """

    parser = argparse.ArgumentParser(prog='attestation-test')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save_file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument('-l',
                           '--ledger-key',
                           help='ledger verifying key',
                           type=str)

    subparser = subparsers.add_parser('get_contract_metadata')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('get_contract_code_metadata')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('add_endpoint')
    subparser.add_argument('-c',
                           '--code-metadata',
                           help='contract code metadata',
                           type=invocation_parameter,
                           required=True)
    subparser.add_argument('-i',
                           '--contract-id',
                           help='contract identifier',
                           type=str,
                           required=True)
    subparser.add_argument('-l',
                           '--ledger-attestation',
                           help='attestation from the ledger',
                           type=invocation_parameter,
                           required=True)
    subparser.add_argument('-m',
                           '--contract-metadata',
                           help='contract metadata',
                           type=invocation_parameter,
                           required=True)

    subparser = subparsers.add_parser('generate_secret')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('send_secret')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('recv_secret')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('reveal_secret')
    subparser.add_argument(
        '-a',
        '--state-attestation',
        help='ledger signature for current state attestation',
        type=invocation_parameter,
        required=True)
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    # -------------------------------------------------------
    if options.command == 'initialize':
        message = invocation_request('initialize',
                                     ledger_verifying_key=options.ledger_key)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'get_contract_metadata':
        extraparams['commit'] = False
        message = invocation_request('get_contract_metadata')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'get_contract_code_metadata':
        extraparams['commit'] = False
        message = invocation_request('get_contract_code_metadata')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'add_endpoint':
        message = invocation_request(
            'add_endpoint',
            contract_id=options.contract_id,
            ledger_attestation=options.ledger_attestation,
            contract_metadata=options.contract_metadata,
            contract_code_metadata=options.code_metadata)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'generate_secret':
        message = invocation_request('generate_secret')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'send_secret':
        return

    # -------------------------------------------------------
    if options.command == 'recv_secret':
        return

    # -------------------------------------------------------
    if options.command == 'reveal_secret':
        extraparams['commit'] = False
        message = invocation_request(
            'reveal_secret', ledger_signature=options.state_attestation)
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return
def __command_issuer__(state, bindings, pargs):
    """controller command to interact with an issuer contract
    """

    parser = argparse.ArgumentParser(prog='issuer')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save_file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_verifying_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('get_balance')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument(
        '-t',
        '--type_id',
        help='contract identifier for the issuer asset type',
        type=str,
        required=True)
    subparser.add_argument(
        '-a',
        '--authority',
        help='serialized authority from the vetting organization',
        type=str,
        required=True)

    subparser = subparsers.add_parser('issue')
    subparser.add_argument('-o',
                           '--owner',
                           help='identity of the issuance owner; ECDSA key',
                           type=str,
                           required=True)
    subparser.add_argument('-c',
                           '--count',
                           help='amount of the issuance',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('transfer')
    subparser.add_argument('-n',
                           '--new_owner',
                           help='identity of the new owner; ECDSA key',
                           type=str,
                           required=True)
    subparser.add_argument('-c',
                           '--count',
                           help='amount to transfer',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('escrow')  # combine escrow & attestation
    subparser.add_argument('-a',
                           '--agent',
                           help='identity of the escrow agent',
                           type=str,
                           required=True)
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('disburse')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Disburse attestation from the escrow agent',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('claim')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Disburse attestation from the escrow agent',
                           type=str,
                           required=True)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    # -------------------------------------------------------
    if options.command == 'get_verifying_key':
        extraparams['commit'] = False
        message = "'(get-verifying-key)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'get_balance':
        extraparams['commit'] = False
        message = "'(get-balance)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'initialize':
        message = "'(initialize \"{0}\" {1})".format(options.type_id,
                                                     options.authority)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'issue':
        message = "'(issue \"{0}\" {1})".format(options.owner, options.count)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'transfer':
        message = "'(transfer \"{0}\" {1})".format(options.new_owner,
                                                   options.count)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'escrow':
        extraparams['commit'] = True
        extraparams['wait'] = True
        message = "'(escrow \"{0}\")".format(options.agent)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)

        extraparams['commit'] = False
        extraparams['wait'] = False
        message = "'(escrow-attestation)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'disburse':
        attestation = SchemeExpression.ParseExpression(options.attestation)
        dependencies = str(attestation.nth(0))
        signature = str(attestation.nth(1))
        message = "'(disburse {0} {1})".format(dependencies, signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'claim':
        attestation = SchemeExpression.ParseExpression(options.attestation)
        old_owner_identity = str(attestation.nth(0))
        dependencies = str(attestation.nth(1))
        signature = str(attestation.nth(2))
        message = "'(claim {0} {1} {2})".format(old_owner_identity,
                                                dependencies, signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return
def __command_integer_key__(state, bindings, pargs):
    """controller command to interact with an integer-key contract
    """

    parser = argparse.ArgumentParser(prog='integer_key')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save-file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_signing_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('create')
    subparser.add_argument('-k',
                           '--key',
                           help='key to create',
                           type=str,
                           required=True)
    subparser.add_argument('-v',
                           '--value',
                           help='initial value to give to the key',
                           type=int,
                           default=0)

    subparser = subparsers.add_parser('inc')
    subparser.add_argument('-k',
                           '--key',
                           help='key to increment',
                           type=str,
                           required=True)
    subparser.add_argument('-v',
                           '--value',
                           help='initial value to give to the key',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('dec')
    subparser.add_argument('-k',
                           '--key',
                           help='key to decrement',
                           type=str,
                           required=True)
    subparser.add_argument('-v',
                           '--value',
                           help='initial value to give to the key',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('get')
    subparser.add_argument('-k',
                           '--key',
                           help='key to retrieve',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('transfer')
    subparser.add_argument('-k',
                           '--key',
                           help='key to transfer',
                           type=str,
                           required=True)
    subparser.add_argument('-o',
                           '--owner',
                           help='identity to transfer ownership',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('escrow')
    subparser.add_argument('-k',
                           '--key',
                           help='key to escrow',
                           type=str,
                           required=True)
    subparser.add_argument('-a',
                           '--agent',
                           help='identity of the escrow agent',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('attestation')
    subparser.add_argument('-k',
                           '--key',
                           help='key to escrow',
                           type=str,
                           required=True)
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('disburse')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Disburse attestation from the escrow agent',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('exchange')
    subparser.add_argument('-a',
                           '--attestation',
                           help='Disburse attestation from the escrow agent',
                           type=str,
                           required=True)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    if options.command == 'get_signing_key':
        message = "'(get-public-signing-key)"
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'create':
        message = "'(create \"{0}\" {1})".format(options.key, options.value)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'inc':
        message = "'(inc \"{0}\" {1})".format(options.key, options.value)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'dec':
        message = "'(dec \"{0}\" {1})".format(options.key, options.value)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'get':
        extraparams['commit'] = False
        message = "'(get-value \"{0}\")".format(options.key)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'transfer':
        message = "'(transfer-ownership \"{0}\" \"{1}\")".format(
            options.key, options.owner)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'escrow':
        message = "'(escrow \"{0}\" \"{1}\")".format(options.key,
                                                     options.agent)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'attestation':
        message = "'(escrow-attestation \"{0}\")".format(options.key)
        result = send_to_contract(state, options.save_file, options.enclave,
                                  message, **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'disburse':
        attestation = SchemeExpression.ParseExpression(options.attestation)
        assetkey = dict(attestation.nth(0).value)['key']
        dependencies = str(attestation.nth(1))
        signature = str(attestation.nth(2))
        message = "'(disburse \"{0}\" {1} {2})".format(assetkey, dependencies,
                                                       signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return

    if options.command == 'exchange':
        attestation = SchemeExpression.ParseExpression(options.attestation)
        offered = dict(attestation.nth(0).value)['key']
        maxbid = dict(attestation.nth(1).value)['key']
        dependencies = str(attestation.nth(2))
        signature = str(attestation.nth(3))
        message = "'(exchange-ownership \"{0}\" \"{1}\" {2} {3})".format(
            offered, maxbid, dependencies, signature)
        send_to_contract(state, options.save_file, options.enclave, message,
                         **extraparams)
        return
def __command_integer_key__(state, bindings, pargs):
    """controller command to interact with an integer-key contract
    """

    parser = argparse.ArgumentParser(prog='integer_key')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save-file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_state')

    subparser = subparsers.add_parser('get_signing_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('create')
    subparser.add_argument('-k',
                           '--key',
                           help='key to create',
                           type=str,
                           required=True)
    subparser.add_argument('-v',
                           '--value',
                           help='initial value to give to the key',
                           type=int,
                           default=0)

    subparser = subparsers.add_parser('inc')
    subparser.add_argument('-k',
                           '--key',
                           help='key to increment',
                           type=str,
                           required=True)
    subparser.add_argument('-v',
                           '--value',
                           help='initial value to give to the key',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('dec')
    subparser.add_argument('-k',
                           '--key',
                           help='key to decrement',
                           type=str,
                           required=True)
    subparser.add_argument('-v',
                           '--value',
                           help='initial value to give to the key',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('get')
    subparser.add_argument('-k',
                           '--key',
                           help='key to retrieve',
                           type=str,
                           required=True)
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('transfer')
    subparser.add_argument('-k',
                           '--key',
                           help='key to transfer',
                           type=str,
                           required=True)
    subparser.add_argument('-o',
                           '--owner',
                           help='identity to transfer ownership',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('escrow')
    subparser.add_argument('-k',
                           '--key',
                           help='key to escrow',
                           type=str,
                           required=True)
    subparser.add_argument('-a',
                           '--agent',
                           help='identity of the escrow agent',
                           type=str,
                           required=True)

    subparser = subparsers.add_parser('attestation')
    subparser.add_argument('-k',
                           '--key',
                           help='key to escrow',
                           type=str,
                           required=True)
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('disburse')
    subparser.add_argument('-a',
                           '--attestation',
                           help='disburse attestation from escrow agent',
                           type=invocation_parameter,
                           required=True)

    subparser = subparsers.add_parser('exchange')
    subparser.add_argument('-a',
                           '--attestation',
                           help='exchange attestation from escrow agent',
                           type=invocation_parameter,
                           required=True)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    if options.command == 'get_state':
        extraparams['quiet'] = True
        message = invocation_request('get-state')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        __dump_state__(result)
        return

    if options.command == 'get_signing_key':
        message = invocation_request('get-public-signing-key')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'create':
        message = invocation_request('create', options.key, options.value)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'inc':
        message = invocation_request('inc', options.key, options.value)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'dec':
        message = invocation_request('dec', options.key, options.value)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'get':
        extraparams['commit'] = False
        message = invocation_request('get-value', options.key)
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if options.symbol:
            bindings.bind(options.symbol, result)
        return

    if options.command == 'transfer':
        message = invocation_request('transfer-ownership', options.key,
                                     options.owner)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'escrow':
        message = invocation_request('escrow', options.key, options.agent)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'attestation':
        message = invocation_request('escrow-attestation', options.key)
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if options.symbol:
            bindings.bind(options.symbol, json.dumps(result))
        return

    if options.command == 'disburse':
        assert type(options.attestation) is list
        assert len(options.attestation) == 3

        bidinfo = dict(options.attestation[0])
        assetkey = bidinfo['key']
        dependencies = options.attestation[1]
        signature = options.attestation[2]
        message = invocation_request('disburse', assetkey, dependencies,
                                     signature)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    if options.command == 'exchange':
        assert type(options.attestation) is list
        assert len(options.attestation) == 4

        offered = dict(options.attestation[0])['key']
        maxbid = dict(options.attestation[1])['key']
        dependencies = options.attestation[2]
        signature = options.attestation[3]
        message = invocation_request('exchange-ownership', offered, maxbid,
                                     dependencies, signature)
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return
Beispiel #12
0
def __command_auction__(state, bindings, pargs):
    """controller command to interact with an auction contract
    """

    parser = argparse.ArgumentParser(prog='auction')
    parser.add_argument('-e',
                        '--enclave',
                        help='URL of the enclave service to use',
                        type=str)
    parser.add_argument('-f',
                        '--save_file',
                        help='File where contract data is stored',
                        type=str)
    parser.add_argument('-q',
                        '--quiet',
                        help='Suppress printing the result',
                        action='store_true')
    parser.add_argument('-w',
                        '--wait',
                        help='Wait for the transaction to commit',
                        action='store_true')

    subparsers = parser.add_subparsers(dest='command')

    subparser = subparsers.add_parser('get_verifying_key')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('get_offered_asset')
    subparser = subparsers.add_parser('get_requested_asset')

    subparser = subparsers.add_parser('initialize')
    subparser.add_argument(
        '-r',
        '--root',
        help='key for the root authority for requested issuer',
        type=str,
        required=True)
    subparser.add_argument(
        '-t',
        '--type_id',
        help='contract identifier for the requested asset type',
        type=str,
        required=True)
    subparser.add_argument('-o',
                           '--owner',
                           help='identity of the asset owner; ECDSA key',
                           type=str,
                           default="")
    subparser.add_argument('-c',
                           '--count',
                           help='amount requested',
                           type=int,
                           required=True)

    subparser = subparsers.add_parser('offer')
    subparser.add_argument('-a',
                           '--asset',
                           help='serialized escrowed asset',
                           type=scheme_parameter,
                           required=True)

    subparser = subparsers.add_parser('claim_offer')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('cancel_auction')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('close_auction')
    subparser = subparsers.add_parser('confirm_close')

    subparser = subparsers.add_parser('submit_bid')
    subparser.add_argument('-a',
                           '--asset',
                           help='serialized escrowed asset',
                           type=scheme_parameter,
                           required=True)

    subparser = subparsers.add_parser('claim_bid')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    subparser = subparsers.add_parser('max_bid')
    subparser = subparsers.add_parser('check_bid')

    subparser = subparsers.add_parser('cancel_bid')
    subparser.add_argument('-s',
                           '--symbol',
                           help='binding symbol for result',
                           type=str)

    options = parser.parse_args(pargs)

    extraparams = {'quiet': options.quiet, 'wait': options.wait}

    # -------------------------------------------------------
    if options.command == 'get_verifying_key':
        extraparams['commit'] = False
        message = invocation_request('get-verifying-key')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'get_offered_asset':
        extraparams['commit'] = False
        message = invocation_request('examine-offered-asset')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'get_requested_asset':
        extraparams['commit'] = False
        message = invocation_request('examine-requested-asset')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'initialize':
        asset_request = [options.type_id, options.count, options.owner]
        message = invocation_request('initialize', asset_request, options.root)
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'offer':
        message = invocation_request('offer-asset', options.asset)
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'claim_offer':
        extraparams['commit'] = False
        message = invocation_request('claim-offer')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'cancel_auction':
        message = invocation_request('cancel-auction')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result == "#t":
            extraparams['commit'] = False
            message = invocation_request('cancel-auction-attestation')
            send_to_contract(state,
                             options.save_file,
                             message,
                             eservice_url=options.enclave,
                             **extraparams)
            if result and options.symbol:
                bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'close_auction':
        message = invocation_request('close-auction')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'confirm_close':
        message = invocation_request('confirm-close')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'submit_bid':
        message = invocation_request('submit-bid', options.asset)
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'max_bid':
        extraparams['commit'] = False
        message = invocation_request('max-bid')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'check_bid':
        extraparams['commit'] = False
        message = invocation_request('check-bid')
        send_to_contract(state,
                         options.save_file,
                         message,
                         eservice_url=options.enclave,
                         **extraparams)
        return

    # -------------------------------------------------------
    if options.command == 'claim_bid':
        extraparams['commit'] = False
        message = invocation_request('claim-bid')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result and options.symbol:
            bindings.bind(options.symbol, result)
        return

    # -------------------------------------------------------
    if options.command == 'cancel_bid':
        message = invocation_request('cancel-bid')
        result = send_to_contract(state,
                                  options.save_file,
                                  message,
                                  eservice_url=options.enclave,
                                  **extraparams)
        if result == "#t":
            extraparams['commit'] = False
            message = invocation_request('cancel-bid-attestation')
            result = send_to_contract(state,
                                      options.save_file,
                                      message,
                                      eservice_url=options.enclave,
                                      **extraparams)
            if result and options.symbol:
                bindings.bind(options.symbol, result)

        return