Difference between revisions of "JSON-RPC-Commands"

From Snowblossom Wiki
Jump to: navigation, search
(migration)
 
(get_hash_address)
Line 181: Line 181:
 
   "jsonrpc": "2.0"
 
   "jsonrpc": "2.0"
 
}</pre>
 
}</pre>
= get_hash_address =
+
== get_hash_address ==
  
 
Get the address for a given spechash
 
Get the address for a given spechash
Line 450: Line 450:
 
   &quot;jsonrpc&quot;: &quot;2.0&quot;
 
   &quot;jsonrpc&quot;: &quot;2.0&quot;
 
}</pre>
 
}</pre>
 +
 
= MrPlow =
 
= MrPlow =
  

Revision as of 18:05, 4 March 2019

SnowBlossomClient

Turn on rpcserver by running the client with the command 'rpcserver'. This is done to make sure that running the client (with full access to the wallet in question) is intentional. Requires the following config settings, rpc_port, rpc_username, rpc_password.

getfresh

Gets a fresh address. Optional parameters:

  • mark_used - (default: false) if true, mark this address as used so it will not be used as change or returned by other getfresh calls.
  • generate_now - (default: false) rather than using the unused key pool, generate a new address to use
curl -d '{ "jsonrpc": "2.0", "method":"getfresh", "id":"getfresh", "params": { "mark_used": true, "generate_now": true }}' http://cows:two@localhost:11323/
{
  "result": {
    "address": "snowtest:fxuc95w50hkpxjrkhmk3zffxdh3qsd5jkh7v8pq7",
    "mark_used": true,
    "generate_now": true
  },
  "id": "getfresh",
  "jsonrpc": "2.0"
}

balance

Get the wallet balance in both SNOW (double) and flakes.

curl -d '{ "jsonrpc": "2.0", "method":"balance", "id":"balance"}' http://cows:two@localhost:11323/
{
  "result": {
    "unconfirmed": 0,
    "spendable": 376960.914462,
    "flake_confirmed": 376960914462,
    "flake_spendable": 376960914462,
    "confirmed": 376960.914462,
    "flake_unconfirmed": 0
  },
  "id": "balance",
  "jsonrpc": "2.0"
}

send / create_transaction

Create a transaction, possible sign and broadcast snow.

  • broadcast - (default: true) broadcast transaction when done making it
  • sign - (default: true) sign transaction with any keys in current wallet that match
  • outputs - list of outputs to send snow to. Must specify snow or flakes.
  • extra - hex encoded binary data to attach as extra field to transaction

Fee related

  • fee_use_estimate - (default: true) use size based fee estimation for the fee
  • fee_flat - SNOW amount to use as the fee

Input Related

  • input_specific_list - Use only the inputs included in the input array (param: inputs)
  • input_confirmed_then_pending - (default: true) prefer to use confirmed, but use pending if run out of confirmed
  • input_confirmed_only - only use outputs that are confirmed as inputs
  • inputs - Specific list of inputs to use. each one must have, address, src_tx, src_tx_out_idx, and value

Change related

  • split_change_over - Amount of SNOW to split change outputs if in excess of
  • change_random_from_wallet - Use a random address rather than a fresh one. Note this can reuse an addresses that has been used before
  • change_fresh_address - (default: true) use a fresh address
  • change_specific_addresses - only use addresses from the list provided with 'change_addresses'
  • change_addresses - List of change addresses to use as change for this transaction

An example using an obnoxious number of features:

{
  "jsonrpc": "2.0",
  "method": "send",
  "id": "send_test",
  "params": {
    "input_specific_list": true,
    "inputs": [
      {
        "address": "8apcj0hhtxcm9xa2j4gaxxkzz9a3fhp35vjemnff",
        "src_tx": "a27aed7072735ecf50c50c3782470006a854a80f8e472283eea77e5dc0db3f03",
        "src_tx_out_idx": 2,
        "value": 2474999113
      }
    ],
    "split_change_over": 2500,
    "sign": true,
    "broadcast": true,
    "outputs": [
      {
        "address": "snowtest:j4hl7axx24yy9m3pfmag3a3jn26f20rwz3u9jhr9",
        "snow": 25
      },
      {
        "address": "snowtest:u4wmy9c8n56vd9285srvd4928ewm0urru2g7va2m",
        "flakes": 50
      }
    ],
    "change_specific_addresses": true,
    "change_addresses": [
      "snowtest:8apcj0hhtxcm9xa2j4gaxxkzz9a3fhp35vjemnff",
      "m36evc3zlqr4r3uuy6g3r6t3299769cwhldzsehu"
    ]
  }
}
{
  "result": {
    "signatures_added": 1,
    "tx_data": "0a209c73bd7dc38b7789c324c7f554361b9dcbfb8c555d7c61e7c64659ae1ed4339c12c1010801223a0a143f43893ef759b1b29baa9551d31ac2117b14dc311220a27aed
7072735ecf50c50c3782470006a854a80f8e472283eea77e5dc0db3f0318022a1c089283a090091214dc75966222f80751c79c269111e971514bed170e2a1b08c0f0f50b1214956fff74c655
4842ee214efa88f6329ab4953c6e2a1808321214e55db217079d34c69547a406c6d4aa3e5db7f063322908011225080112210219a144311398579e6a0f8c57897e2671376c10a5cbd2e5cae9
a29a7366a429d440c5061a491a473045022100df1ea4cdd520467b43e2bd851a5c9ced3d63d12b87e927a061e64c7621a7ac5702202651bbfb75862ef8ad83e2d0df03cd42319642e6fcece3
39a5678777e2bba621",
    "fee": 837,
    "tx_hash": "9c73bd7dc38b7789c324c7f554361b9dcbfb8c555d7c61e7c64659ae1ed4339c",
    "all_signed": true
  },
  "id": "send_test",
  "jsonrpc": "2.0"
}

sign-transaction

This operation signs the input transaction with any relevant keys that are available. That could be zero keys.

{
  "jsonrpc": "2.0",
  "method": "sign_transaction",
  "id": "signtx8",
  "params": {
    "tx_data": "0a2038e32c8d9ad597cb1a709cd87b0c2f8e94095332842e5b00cac6976b4209b63712c1010801223a0a141417000f56a6fcf03964af73ffb25cad72d0e8e81220f72100b84bfdcb576a5a138766a4aefef992ef92e8c95dea095cc7a34bc84806181c2a1808321214e55db217079d34c69547a406c6d4aa3e5db7f0632a1b08c0f0f50b1214956fff74c6554842ee214efa88f6329ab4953c6e2a1c08c9fa959c091214dc75966222f80751c79c269111e971514bed170e322908011225080112210241a39501924c65162e5ca92dbbda43565b81023da57f802638fd2f72fd88e18940c506"
  }
}
{
  "result": {
    "signatures_added": 1,
    "tx_data": "0a2038e32c8d9ad597cb1a709cd87b0c2f8e94095332842e5b00cac6976b4209b63712c1010801223a0a141417000f56a6fcf03964af73ffb25cad72d0e8e81220f72100b84bfdcb576a5a138766a4aefef992ef92e8c95dea095cc7a34bc84806181c2a1808321214e55db217079d34c69547a406c6d4aa3e5db7f0632a1b08c0f0f50b1214956fff74c6554842ee214efa88f6329ab4953c6e2a1c08c9fa959c091214dc75966222f80751c79c269111e971514bed170e322908011225080112210241a39501924c65162e5ca92dbbda43565b81023da57f802638fd2f72fd88e18940c5061a491a473045022100a5a3d8b81968a15b5a6a19e2e5d712fe65df8dea83c4bdf9ece60b7dc2c2193f0220579ff3598d894239882cafe612f5b82a7944687adcd35a981e2736abeaaa8b1b",
    "fee": 837,
    "tx_hash": "38e32c8d9ad597cb1a709cd87b0c2f8e94095332842e5b00cac6976b4209b637",
    "all_signed": true
  },
  "id": "signtx8",
  "jsonrpc": "2.0"
}

broadcast

This sends the transaction on the network.

{
  "jsonrpc": "2.0",
  "method": "broadcast",
  "id": "cast",
  "params": {
    "tx_data": "0a2038e32c8d9ad597cb1a709cd87b0c2f8e94095332842e5b00cac6976b4209b63712c1010801223a0a141417000f56a6fcf03964af73ffb25cad72d0e8e81220f72100b84bfdcb576a5a138766a4aefef992ef92e8c95dea095cc7a34bc84806181c2a1808321214e55db217079d34c69547a406c6d4aa3e5db7f0632a1b08c0f0f50b1214956fff74c6554842ee214efa88f6329ab4953c6e2a1c08c9fa959c091214dc75966222f80751c79c269111e971514bed170e322908011225080112210241a39501924c65162e5ca92dbbda43565b81023da57f802638fd2f72fd88e18940c5061a491a47304502202aaeeb87db579e5201df9188fc4161d1fc2ef71fc5675d7b30e1cd2906625896022100cb64cb9ecdad42533c69873e05154e10b22f14d3b0c838da9a9ae533adbd5acd"
  }
}
{
  "result": {
    "tx_data": "0a2038e32c8d9ad597cb1a709cd87b0c2f8e94095332842e5b00cac6976b4209b63712c1010801223a0a141417000f56a6fcf03964af73ffb25cad72d0e8e81220f72100b84bfdcb576a5a138766a4aefef992ef92e8c95dea095cc7a34bc84806181c2a1808321214e55db217079d34c69547a406c6d4aa3e5db7f0632a1b08c0f0f50b1214956fff74c6554842ee214efa88f6329ab4953c6e2a1c08c9fa959c091214dc75966222f80751c79c269111e971514bed170e322908011225080112210241a39501924c65162e5ca92dbbda43565b81023da57f802638fd2f72fd88e18940c5061a491a47304502202aaeeb87db579e5201df9188fc4161d1fc2ef71fc5675d7b30e1cd2906625896022100cb64cb9ecdad42533c69873e05154e10b22f14d3b0c838da9a9ae533adbd5acd",
    "fee": 837,
    "tx_hash": "38e32c8d9ad597cb1a709cd87b0c2f8e94095332842e5b00cac6976b4209b637"
  },
  "id": "cast",
  "jsonrpc": "2.0"
}

get_address_hash

Get the hex spechash for an address.

{
  "jsonrpc": "2.0",
  "method": "get_address_hash",
  "id": "0",
  "params": {
    "address": "snowtest:08n4fjwyuwxuc54y3m67mrgl9qgc8wylrahjpyxd"
  }
}
{
  "result": {
    "address": "snowtest:08n4fjwyuwxuc54y3m67mrgl9qgc8wylrahjpyxd",
    "spechash": "79e754c9c4e38dcc52a48ef5ed8d1f281183b89f"
  },
  "id": "0",
  "jsonrpc": "2.0"
}

get_hash_address

Get the address for a given spechash

{
  "jsonrpc": "2.0",
  "method": "get_hash_address",
  "id": "0",
  "params": {
    "spechash": "79e754c9c4e38dcc52a48ef5ed8d1f281183b89f"
  }
}
{
  "result": {
    "address": "snowtest:08n4fjwyuwxuc54y3m67mrgl9qgc8wylrahjpyxd",
    "spechash": "79e754c9c4e38dcc52a48ef5ed8d1f281183b89f"
  },
  "id": "0",
  "jsonrpc": "2.0"
}

parse_transaction

For the given tx_data, give a json version of the transaction. If any integers are oddly missing, they are probably zero, which protobuf omits as default. All byte strings are as base64 even though everything else uses hex for json interface.

{
  "jsonrpc": "2.0",
  "method": "parse_transaction",
  "id": "0",
  "params": {
    "tx_data": "0a201b7d5d0502dfe5de22c5fb30e58fef20dc332da51e3e0ef55c061ba79c616ca012a601080122380a1439484a240082fffe5c588618ac612080801de1fe12207360a94dc251c4a7fdd7465fcc98c3f6753de7fbc89fbd005bb3dafa89f4d6772a1d08c1f1f795ba0112141b8522585858bfd2934ae14c6f119bb6976e88172a1b08c0f0f50b1214956fff74c6554842ee214efa88f6329ab4953c6e322908011225080112210235762013f9aa121b588e745e4cc62267973763997d150edc430f1a68c45117e840ff051a481a463044022018b4698d72102eba38bb49f0ede1472a3b838f6464b0399de3349e5c3e1d5589022036b69c76f35fa5ff0622f6a67cf51f5da86938bde9fd0fd1592f7b1f09721b33"
  }
}
{
  "result": {
    "tx": {
      "innerData": "CAEiOAoUOUhKJACC//5cWIYYrGEggIAd4f4SIHNgqU3CUcSn/ddGX8yYw/Z1Pef7yJ+9AFuz2vqJ9NZ3Kh0IwfH3lboBEhQbhSJYWFi/0pNK4UxvEZu2l26IFyobCMDw9QsSFJVv/3TGVUhC7iFO+oj2Mpq0lTxuMikIARIlCAESIQI1diAT+aoSG1iOdF5MxiJnlzdjmX0VDtxDDxpoxFEX6ED/BQ==",
      "txHash": "G31dBQLf5d4ixfsw5Y/vINwzLaUePg71XAYbp5xhbKA=",
      "signatures": [
        {
          "signature": "MEQCIBi0aY1yEC66OLtJ8O3hRyo7g49kZLA5neM0nlw+HVWJAiA2tpx281+l/wYi9qZ89R9dqGk4ven9D9FZL3sfCXIbMw=="
        }
      ]
    },
    "inner": {
      "outputs": [
        {
          "recipientSpecHash": "G4UiWFhYv9KTSuFMbxGbtpduiBc=",
          "value": "49974999233"
        },
        {
          "recipientSpecHash": "lW//dMZVSELuIU76iPYymrSVPG4=",
          "value": "25000000"
        }
      ],
      "inputs": [
        {
          "srcTxId": "c2CpTcJRxKf910ZfzJjD9nU95/vIn70AW7Pa+on01nc=",
          "specHash": "OUhKJACC//5cWIYYrGEggIAd4f4="
        }
      ],
      "fee": "767",
      "claims": [
        {
          "sigSpecs": [
            {
              "signatureType": 1,
              "publicKey": "AjV2IBP5qhIbWI50XkzGImeXN2OZfRUO3EMPGmjEURfo"
            }
          ],
          "requiredSigners": 1
        }
      ],
      "version": 1
    }
  },
  "id": "0",
  "jsonrpc": "2.0"
}

get_transaction

Get the hex bytes for a transaction and also its status.

{
  "jsonrpc": "2.0",
  "method": "get_transaction",
  "id": "0",
  "params": {
    "tx_hash": "a07228f2313a76d468412a439cc87a87389761a67950c32c898d47edcbb8a1df"
  }
}
{
  "result": {
    "tx_data": "0a20a07228f2313a76d468412a439cc87a87389761a67950c32c898d47edcbb8a1df12a501080122380a1452013f3cd4296235158f708db2c52390f2c195f0122016530e2573da7c84f9104af6ee5d6ef31e7423b440f827d801c74e48b37d43c42a1b08c0f0f50b1214956fff74c6554842ee214efa88f6329ab4953c6e2a1c08c199e9b44a12147952bcad957f1164142c7947aeba9176f80c534c3229080112250801122102a27ab7714f04fa86be92e82daad876451b6b575945c0820b9342a94d35821e6b40ff051a4a1a483046022100c21f0859d972724310e8d52888c73c9d8f648e2fa0492369327f38094ce8eca5022100941254d6b3fced1d5b90e88c5a44d0b7d00907a9756030f4e22513134db28dbe",
    "fee": 767,
    "tx_hash": "a07228f2313a76d468412a439cc87a87389761a67950c32c898d47edcbb8a1df",
    "status": {
      "heightConfirmed": 13672,
      "confirmations": 2,
      "confirmed": true
    }
  },
  "id": "0",
  "jsonrpc": "2.0"
}

get_unspent

Get all unspent outputs.

{
  "jsonrpc": "2.0",
  "method": "get_unspent",
  "id": "0"
}
{
  "result": {
    "unspent": [
      {
        "address": "snowtest:y7mwxfv799l3lwqw4dcfmdzdql3ghtyuakm72le5",
        "src_tx_out_idx": 0,
        "src_tx": "d12824a0f6bdf10d697a85eed8e609ddc6f5f0823c862d8cf363e4438635b55f",
        "value": 400000000000,
        "confirmed": true
      },
      {
        "address": "snowtest:kwv3dsf5jlvlmgerhjy56wrhjf2rfr4ucm07wnep",
        "src_tx_out_idx": 0,
        "src_tx": "3855df061bb6ece61a51329380f70988bdbe999f3093976b882c4b6fde29e978",
        "value": 14999999093,
        "confirmed": true
      },
      {
        "address": "snowtest:u62g3790cg4lm0gsz6q8jtm3025zt5yn2en77scm",
        "src_tx_out_idx": 1,
        "src_tx": "40871fcabd7e029920c58c82ea5d28fb947f9ec832389c31a35b826777eb8676",
        "value": 45852000000,
        "confirmed": true
      },
      {
        "address": "snowtest:rwzjykzctzla9y62u9xx7yvmk6tkazqhenp48f0p",
        "src_tx_out_idx": 0,
        "src_tx": "1b7d5d0502dfe5de22c5fb30e58fef20dc332da51e3e0ef55c061ba79c616ca0",
        "value": 49974999233,
        "confirmed": true
      },
      {
        "address": "snowtest:09ftetv40ugkg9pv09r6aw53wmuqc56v5klwwyy0",
        "src_tx_out_idx": 1,
        "src_tx": "a07228f2313a76d468412a439cc87a87389761a67950c32c898d47edcbb8a1df",
        "value": 19974999233,
        "confirmed": true
      },
      {
        "address": "snowtest:js0e77fm3kx47a3p8uwe2apk6tzuj8xudjzjyhsh",
        "src_tx_out_idx": 1,
        "src_tx": "a68bf5ef06915a979290b2b2076bb2ef618921522bdce12d5e7f907911a58ac5",
        "value": 12430000000,
        "confirmed": true
      }
    ]
  },
  "id": "0",
  "jsonrpc": "2.0"
}

get_status

Returns node status and balance.

{
  "jsonrpc": "2.0",
  "method": "get_status",
  "id": "0"
}
{
  "result": {
    "node_status": {
      "connectedPeers": 6,
      <BUNCH MORE NODE STATUS STUFF, SUPER FUN>
      ...
    },
    "balance": {
      "spendable": "543231997559",
      "unconfirmed_snow": 0,
      "spendable_snow": 543231.997559,
      "confirmed": "543231997559",
      "confirmed_snow": 543231.997559
    }
  },
  "id": "0",
  "jsonrpc": "2.0"
}

import_wallet

Imports wallet data, in the same format used by the command line 'export', 'export_watch_only' and 'import' commands.

The format for the private key is PKCS8 encoded base64. The format for the public key is X509 encoded base64. On import, the public and private key pair are tested to make sure Snowblossom can parse them and that something signed with the private key is verified by the public key.

Example with just an address spec for watch only wallet

{
  "jsonrpc": "2.0",
  "method": "import_wallet",
  "id": "import",
  "params": {
    "wallet": {
      "addresses": [
        {
          "requiredSigners": 1,
          "sigSpecs": [
            {
              "signatureType": 1,
              "publicKey": "A91uzlbcu9kO2dSDj6VWzu2Z8zZN/sNP1411hWCDFivl"
            }
          ]
        }
      ]
    }
  }
}
{
  "result": {
    "addresses": [
      "snowtest:kumvfk3070dknv00xzjhf4jq2pezk477nv0nm6g7"
    ],
    "keys": []
  },
  "id": "import",
  "jsonrpc": "2.0"
}

Example with a public and private key pair and associated address:

{
  "jsonrpc": "2.0",
  "method": "import_wallet",
  "id": "import",
  "params": {
    "wallet": {
      "keys": [
        {
          "signatureType": 1,
          "publicKey": "A91uzlbcu9kO2dSDj6VWzu2Z8zZN/sNP1411hWCDFivl",
          "privateKey": "MIGNAgEAMBAGByqGSM49AgEGBSuBBAAKBHYwdAIBAQQgZ8mfHBR27RX5KjoSxbJf/n1maefiYqaY3gVxFne4mZCgBwYFK4EEAAqhRANCAATdbs5W3LvZDtnUg4+lVs7tmfM2Tf7DT9eNdYVggxYr5SOAZXVYaC4xpLNjXl2ULU09mZeAj8EyumriVusVELMJ"
        }
      ],
      "addresses": [
        {
          "requiredSigners": 1,
          "sigSpecs": [
            {
              "signatureType": 1,
              "publicKey": "A91uzlbcu9kO2dSDj6VWzu2Z8zZN/sNP1411hWCDFivl"
            }
          ]
        }
      ]
    }
  }
}
{
  "result": {
    "addresses": [
      "snowtest:kumvfk3070dknv00xzjhf4jq2pezk477nv0nm6g7"
    ],
    "keys": [
      "03dd6ece56dcbbd90ed9d4838fa556ceed99f3364dfec34fd78d75856083162be5"
    ]
  },
  "id": "import",
  "jsonrpc": "2.0"
}

MrPlow

If an rpc_port is specified, then MrPlow supports RPC commands.

getfoundblocks

returns number of found blocks and lists them, most recent first

curl -d '{ "jsonrpc": "2.0", "method":"getfoundblocks", "id":"whatever"}' http://localhost:13331/
{
  "result": {
    "found_blocks": 6,
    "hashes": [
      "000000ee7e172390dbd6a477aad2d5be6c4abe531f13efe16f95e0d83e6d0e21",
      "00000027caf1e5f135ef523dc6b44f8eb338fe8a5c3bfb55734a15b0f99cb486",
      "000000e804d55f2253f2df37d83028b6643f680d0e01edcf663e907790b57d19",
      "0000007758531fd85463dc4e2ec8a3b803655cfab6f4ba11e904d4e297849068",
      "000000c6fd193a348ed4dfb01e32bd7947a85e6acda62647aa0beadb6c835fac",
      "000000202452850901943ce74b8e3b55fc51b30ac21259ba21b090715a7182d3"
    ]
  },
  "id": "whatever",
  "jsonrpc": "2.0"
}

getstats

returns a variety of current statistics

curl -d '{ "jsonrpc": "2.0", "method":"getstats", "id":"whatever"}' http://localhost:13331/ | jq .
{
  "result": {
    "found_blocks": 7,
    "share_map": {
      "snowtest:czq7040pjz97vt3smu5maz594juw033duaf4v6yu": 22
    },
    "rates": {
      "total": {
        "60000": 69905.06666666667,
        "300000": 13981.013333333334,
        "900000": 4660.337777777778,
        "3600000": 1165.0844444444444
      },
      "miners": {
        "snowtest:czq7040pjz97vt3smu5maz594juw033duaf4v6yu": {
          "60000": 69905.06666666667,
          "300000": 13981.013333333334,
          "900000": 4660.337777777778,
          "3600000": 1165.0844444444444
        }
      }
    },
    "connections": 1
  },
  "id": "whatever",
  "jsonrpc": "2.0"
}