Giter Site home page Giter Site logo

openapi_spec's Introduction

openapi_spec

openapi_spec's People

Contributors

stdevmac avatar

Watchers

James Cloos avatar

openapi_spec's Issues

Create wallet API endpoint

Original issue: fibercrypto/skyxcommons#6 (comment)
Implement [POST] api/wallets

Should create a new wallet (address) in the blockchain.

Response:

{
 // Private key, which will be used to
 // sign transactions by the [POST] /api/sign
“privateKey”: ”string”,
 // Address which identifies the wallet in the blockchain
“publicAddress”: “string”,
 // Any non security sensitive data associated with
 // wallet. This context will be passed to
 // [POST] /api/transactions/*. 
 // Can be empty.
 “addressContext”: “string”
}

Python implementation

def create_wallet():
    """
    Create the wallet in blockchain
    """

    # generate CSRF token
    CSRF_token = app.session.get(form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/csrf")).json()

    if not CSRF_token or "csrf_token" not in CSRF_token:
        return {"status": 500, "error": "Unknown server error"}

    # generate new seed
    new_seed = app.session.get(
        form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/wallet/newSeed?entropy=128"),
        headers={'X-CSRF-Token': CSRF_token['csrf_token']}).json()

    if not new_seed or "seed" not in new_seed:
        return {"status": 500, "error": "Unknown server error"}

    # create the wallet from seed
    resp = app.session.post(form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/wallet/create"),
                         {"seed": new_seed["seed"],
                             "label": app_config.WALLET_LABEL, "scan": "10"},
                         headers={'X-CSRF-Token': CSRF_token['csrf_token']})

    if not resp:
        return {"status": 500, "error": "Unknown server error"}

    if resp.status_code != 200:
        return {"status": 500, "error": "Unknown server error"}

    new_wallet = resp.json()

    if not new_wallet or "entries" not in new_wallet:
        return {"status": 500, "error": "Unknown server error"}

    seed = new_seed['seed']
    pubkey = skycoin.cipher_PubKey()
    seckey = skycoin.cipher_SecKey()
    error = skycoin.SKY_cipher_GenerateDeterministicKeyPair(
            seed.encode(), pubkey, seckey)
    if error != 0:
        return {"status": 500, "error": "Unknown server error"}

    return {
        "privateKey": binascii.hexlify(bytearray(seckey.toStr())).decode('ascii'),
        "publicAddress": new_wallet["entries"][0]["address"],
        "addressContext": new_wallet['meta']['filename']
    }

[api] Get broadcast tx many-outputs

Original Issue: fibercrypto/skyxcommons#19
[GET] /api/transactions/broadcast/many-outputs/{operationId}

See [GET] /api/capabilities

Should return broadcasted transaction by operation ID . All transactions with many
outputs, that were broadcasted by the [POST] /api/transactions/broadcast should be available here.

Response:

{
// Operation ID.
“operationId”: “guid”,
// State of the transaction
// enum values:
//
// -  inProgress : transaction is being in-progress
// -  completed : transaction is completed for sure. When
// transaction is switched to the completed state, 
// amount of this transaction should be already subtracted from
// the balance returned by the  [GET] /api/balances , 
// for outgoing transactions
// -  failed : transaction is failed
“state”: “enum”,
 // Transaction moment as ISO 8601 in UTC
“timestamp”: “datetime”,
// Source address
“fromAddress”: “string”,
// Destinations.
// Should be non null if the  state is  Completed.
“outputs”: [
{
// Destination address
“toAddress”: “string”,
// Actual amount that is transferred to the
//  toAddress . Integer as string, aligned
// to the asset accuracy. Actual value can be
// calculated as
// x = amount / (10 ^ asset.Accuracy)
“amount”: “string”
} ],
//  Fee. Is integer as string, aligned
   // to the asset accuracy. Actual value can be
   // calculated as
   // x = sourceFee * (10 ^ asset.Accuracy)
// Should be non empty if the  state is  Completed
“fee”: “string”,
   // Transaction hash as base64 string.
   // Can be empty
// Should be non empty if the  state is  Completed
    “hash”: “string”,
// Error description
// Can be empty
// Should be non empty if the  state is  Error
“error”: “string”,
// Error code.
// Can be empty.
// Should be non empty if the state is Failed.
// enum values:
// -  unknown : any error that does not fit another codes.
// -  amountIsTooSmall : amount is too small to execute
// transaction
// -  notEnoughBalance : transaction can’t be executed due
// to balance insufficiency on the source address.
// Should be non empty if the  state is  Error
“errorCode”: “enum”,
// Incremental ID of the moment, when the transaction
// state changing is detected. It should be the same
// sequence as for block in the  [GET] /api/balances
// response. In other words block number/height.
    “block”: integer64
}

Errors:

* `204 No content`  - specified transaction not found

Sign API endpoint

Original Issue: fibercrypto/skyxcommons#5

Implement [POST] api/sign

[POST] /api/sign
Should sign given transaction with the given private key Body:
{
 // Private keys, which were returned by the
 //  [POST] /api/wallets.  Multiple keys can be used
 // for transactions with multiple inputs
"privateKeys": [
"string" ],
 // The transaction context in the blockchain
 // specific format
 //  [POST] /api/transactions or  [PUT] /api/transactions
"transactionContext": "string"
}

Response:

{
 // Signed transaction, which will be used to broadcast
 // the transaction
 // [PUT] /api/transactions/broadcast
 “signedTransaction”: “string”
}

Python implementation

@api.route('/sign', methods=['POST'])
def post_sign():
    """
    Sign transacction with private key
    """
    if not request.json:
        return make_response(jsonify(build_error('Invalid Input Format', error_codes.badFormat)), 400)

    if "privateKeys" not in request.json:
        return make_response(jsonify(build_error('Invalid Input Parameters', error_codes.missingParameter)), 400)

    if "transactionContext" not in request.json:
        return make_response(jsonify(build_error('Invalid Input Parameters', error_codes.missingParameter)), 400)

    private_keys = request.json['privateKeys']
    signedHashHex = request.json['transactionContext']
    for secKey in private_keys:
        signedHashHex = sign_hash(signedHashHex, secKey)
    return signedHashHex

[api] Get broadcast many-inputs

Original Issue: fibercrypto/skyxcommons#20
[GET] /api/transactions/broadcast/many-inputs/{operationId}

Should return broadcasted transaction by the opreationId. All transactions with many inputs, that were broadcasted by the should be available here.

Response:

{
// Operation ID.
“operationId”: “guid”,
// State of the transaction
// enum values:
//
// -  inProgress : transaction is being in-progress
// -  completed : transaction is completed for sure. When
// transaction is switched to the completed state,
// amount of this transaction should be already subtracted
// from the balance returned by the  [GET] /api/balances ,
// for outgoing transactions
// -  failed : transaction is failed, if applicable for the particular blockchain
//
“state”: “enum”,

 // Transaction moment as ISO 8601 in UTC
“timestamp”: “datetime”,
 // Sources.
// Should be non null if the  state is  Completed.
“inputs”: [
{
        “amount”: “string”
    }
// From address
“fromAddress”: “string”,
// Actual amount, that is transferred from the
//  fromAddress . Integer as string, aligned
// to the asset accuracy. Actual value can be
// calculated as
// x = amount / (10 ^ asset.Accuracy)
],
// Destination address
    “toAddress”: “string”,
//  Fee should always be zero if the  state is  Completed
“fee”: “string”,
   // Transaction hash as base64 string.
   // Can be empty
// Should be non empty if the  state is  Completed
    “hash”: “string”,
// Error description
// Can be empty
// Should be non empty if the  state is  Error
“error”: “string”,
// Error code.
// Can be empty.
// Should be non empty if the state is Failed.
// enum values:
// -  unknown : any error that does not fit another codes.
// -  amountIsTooSmall : amount is too small to execute
// transaction
// -  notEnoughBalance : transaction can’t be executed due
// to balance insufficiency on the source address.
“errorCode”: “enum”,
// Incremental ID of the moment, when the transaction
// state changing is detected. It should be the same
// sequence as for block in the  [GET] /api/balances
// response. In other words block number/height.
    “block”: integer64
}

Errors:

* `204 No content`  - specified transaction not found

Delete observation API endpoint

Original issue: fibercrypto/skyxcommons#10 (comment)

[DELETE] /api/balances/{address}/observation

Should forget the wallet address and stop observing its balance.

Errors:
■ 204 No content - specified address is not observed

Python implementation

@api.route('/balances/<string:address>/observation', methods=['DELETE'])
def delete_observation(address):
    """
    Delete the specified address from observation list
    """

    result = delete_address_observation(address)

    # if successfully deleted from observation list, return a plain 200
    if "error" in result:
        return make_response(jsonify(build_error(result["error"])), result["status"])
    else:
        return ""

[api] Get broadcasted tx for op

Original Issue: fibercrypto/skyxcommons#21
[GET] /api/transactions/broadcast/single/{operationId}

Should return broadcasted transaction by the operationId . All transactions with single input and output, that were broadcasted by the [POST] /api/transactions/broadcast should be available here.

{
// Operation ID.
“operationId”: “guid”,
// State of the transaction
// enum values:
// -  inProgress : transaction is being in-progress
// -  completed : transaction is completed for sure
// -  failed : transaction is failed, if applicable for the
//     particular blockchain
“state”: “enum”,
 // Transaction moment as ISO 8601 in UTC
“timestamp”: “datetime”,
//  Amount without fee.
// Is integer as string, aligned to the asset accuracy.
// Actual value can be calculated as
// x = sourceAmount * (10 ^ asset.Accuracy)
// Should be non empty if the  state is  Completed
“amount”: “string”,
//  Fee should be zero if the  state is  Completed
    “fee”: “string”,
   // Transaction hash as base64 string.
   // Can be empty
// Should be non empty if the  state is  Completed
    “hash”: “string”,
// Error description
// Can be empty
// Should be non empty if the  state is  Error
“error”: “string”,
// Error code.
// Can be empty.
// Should be non empty if the state is Failed.
// enum values:
// -  unknown : any error that does not fit another codes.
// -  amountIsTooSmall : amount is too small to execute
// transaction
// -  notEnoughBalance : transaction can’t be executed due
// to balance insufficiency on the source address.
// Should be non empty if the  state is  Error
“errorCode”: “enum”,
// Incremental ID of the moment, when the transaction
// state changing is detected. It should be the same
// sequence as for block in the  [GET] /api/balances
// response. In other words, block number/height.
    “block”: integer64
}

Errors:

* `204 No content`  - specified transaction not found

IsAlive API endpoint

Original Issue: fibercrypto/skyxcommons#4
[GET] /api/isalive

Should return some general service info. Used to check if the service is running. Response:

{
// Name of the service
“name”: “string”,
// Version of the service
“version”: “string”,
// ENV_INFO environment variable value
“env”: “string”,
// Flag, which indicates if the service is built
// in the debug configuration or not
“isDebug”: boolean
}

Python implementation

@api.route('/isalive', methods=['GET'])
def isalive():
    """
    Return some general service info. Used to check if service is running
    """

    version = get_version()

    if "error" in version:
        return make_response(
            jsonify(build_error(version["error"])),
            version["status"]
        )

    result = {
        "name": app.config['SKYCOIN_FIBER_NAME'],
        "version": version,
        "env": app.config["ENVIRONMENT"],
        "isDebug": app.config["DEBUG"],
        "contractVersion": app.config['SWAGGER_API_VERSION']
    }

    return jsonify(result)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.