{
    "$meta": {
        "description": "A `wallet` object can be obtained by either using [create_wallet](#BLOCKCHAIN_CREATE_WALLET) or [login_wallet](#BLOCKCHAIN_LOGIN_WALLET). The `classID` used for this object is `\"wallet\"`."
    },
    "list_coins": {
        "description": "Returns a `list` where each item is a `string` with the names of the coins available in the `wallet`. On failure this method returns a `string` with an error message.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "print \"My wallet is connected to: \" + wallet.list_coins.join(\", \")"
        ]
    },
    "get_balance": {
        "description": "Returns a `number` of coins of a given currency. In case of error, a `string` with the details is returned. If the passed coinName is anything other than a `string` this method will return `null`.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "for coinName in wallet.list_coins",
            "    print \"You have \" + wallet.get_balance(coinName) + \" coins of the currency \"\"\" + coinName + \"\"\"\"",
            "end for"
        ]
    },
    "buy_coin": {
        "description": "Publishes a purchase offer indicating the number of coins you wish to buy and the price ($) per unit you are willing to pay. The purchase will be finalized if there is any sale offer with a price less than or equal to the one proposed in the purchase. If there is no eligible offer to sell at that time, the offer to buy will remain publicly visible until a new offer to sell satisfies the requirements. If the publication has been successful, a `number` with the value one is returned. In case of error, a `string` with the details is returned. Any deviation from the method signature will result in a runtime exception preventing further script execution.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = login_wallet(blockchain, \"test\", \"test\")",
            "result = wallet.buy_coin(\"test\", 100, 20, \"test\")",
            "if result == 1 then",
            "    print \"Sucessfully created purchase offer!\"",
            "else",
            "    print \"Failed: \" + result",
            "end if"
        ]
    },
    "sell_coin": {
        "description": "Publishes a sale offer indicating the amount of coins you want to sell and the price ($) per unit you want to assign. The sale will be finalized if there is any purchase offer with a price greater than or equal to that proposed in the sale. If there is no existing offer to buy that matches the requirements at that time, the offer to sell will remain publicly visible until a new offer to buy satisfies the requirements. If the publication has been successful, a `number` with the value one is returned. In case of error, a `string` with the details is returned. Any deviation from the method signature will result in a runtime exception preventing further script execution.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = login_wallet(blockchain, \"test\", \"test\")",
            "result = wallet.sell_coin(\"test\", 100, 20, \"test\")",
            "if result == 1 then",
            "    print \"Sucessfully created sell offer!\"",
            "else",
            "    print \"Failed: \" + result",
            "end if"
        ]
    },
    "get_pending_trade": {
        "description": "Returns a `list` with the pending sale or purchase offer of this wallet for a certain currency. Index 0 of the `list` represents the type of offer with a `string` (Buy/Sell), index 1 represents the quantity to be sold or bought, and index 2 represents the price per unit. On failure, this method will return a `string` with details. Any deviation from the method signature will result in a `null`.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "result = wallet.get_pending_trade(\"test\")",
            "isBuying = result[0] == \"Buy\"",
            "quantity = result[1]",
            "unitPrice = result[2]",
            "currentBalance = wallet.get_balance(\"test\")",
            "if isBuying then",
            "    print \"After buying was successful your balance will be \" + (quantity * unitPrice + currentBalance)",
            "else",
            "    print \"After selling was successful your balance will be \" + (currentBalance - quantity * unitPrice)",
            "end if"
        ]
    },
    "cancel_pending_trade": {
        "description": "Cancel any pending offer of a certain coin. On success, an empty `string` will be returned. On failure, a `string` with an error message will be returned. Any deviation from the method signature will result in `null`.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "if wallet.cancel_pending_trade(\"test\") == \"\" then",
            "    print \"Trade got canceled!\"",
            "end if"
        ]
    },
    "get_global_offers": {
        "description": "Returns a `map` with all the offers made by any player of a given currency. The key of the `map` represents the WalletID of the player who has made the offer, and the value of the `map` is a `list` where index 0 represents the type of offer with a `string` (Buy/Sell), index 1 represents the amount to sell or buy, and index 2 represents the price per unit. In case of failure, this method returns a `string` with details. Any deviation from the method signature will result in `null`.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "for item in wallet.get_global_offers(\"test\")",
            "    walletId = item.key",
            "    trade = item.value",
            "    isBuying = trade[0] == \"Buy\"",
            "    quantity = trade[1]",
            "    unitPrice = trade[2]",
            "    print \"-\" * 10",
            "    print \"<b>\" + walletId + \"</b>\"",
            "    if isBuying then",
            "        print \"<color=green>Is buying</color>\"",
            "    else",
            "        print \"<color=yellow>Is selling</color>\"",
            "    end if",
            "    print quantity + \" coins with a unit price of \" + unitPrice",
            "end for"
        ]
    },
    "list_global_coins": {
        "description": "Returns a `list` where each item is a `string` containing the names of all the currencies that exist. In case of failure, this method returns a `string` with details.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "print \"All existing coins: \" wallet.list_global_coins.join(\", \")"
        ]
    },
    "show_nodes": {
        "description": "Returns a `number` representing the count of devices mining a specific coin for the same `wallet`. In case of an error, a `string` with details is returned. Any deviation from the method signature will result in `null`.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = login_wallet(blockchain, \"test\", \"test\")",
            "print \"Active miners: \" show_nodes(wallet, \"test\")"
        ]
    },
    "reset_password": {
        "description": "Change the password of the wallet. Only the account owner can perform this action. If the process is completed successfully, a `number` with the value one will be returned. In case of an error, a `string` with details will be returned. Any deviation from the method signature will result in `null`.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "if wallet.reset_password(\"test\") == 1 then",
            "    print \"You got a new password!\"",
            "end if"
        ]
    },
    "get_pin": {
        "description": "Returns a `string` with a PIN that refreshes every few minutes. This PIN is used to obtain an account in cryptocurrency services.",
        "example": [
            "blockchain = include_lib(\"/lib/blockchain.so\")",
            "myShell = get_shell",
            "myComputer = myShell.host_computer",
            "wallet = blockchain.login_wallet(\"test\", \"test\")",
            "myComputer.touch(\"/root\", \"pin_launch.src\")",
            "myFile = myComputer.File(\"/root/pin_launch.src\")",
            "myFile.set_content(\"",
            "    blockchain = include_lib(\"\"/lib/blockchain.so\"\")",
            "    myShell = get_shell",
            "    myComputer = myShell.host_computer",
            "    wallet = blockchain.login_wallet(\"\"test\"\", \"\"test\"\")",
            "    if params[0] ==  wallet.get_pin then",
            "        get_custom_object.secret = \"\"The answer is 42\"\"",
            "    else",
            "        get_custom_object.secret = \"\"The answer is 10053\"\"",
            "    end if",
            "\")",
            "myShell.build(\"/root/pin_launch.src\", \"/root\")",
            "myFile.delete",
            "myShell.launch(\"/root/pin_launch\", wallet.get_pin)",
            "print \"The secret: \" + get_custom_object.secret"
        ]
    }
}
