From c5819a55b5f7b0fa02f04311aa5d7c683c402f60 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Mon, 26 Oct 2020 17:14:16 -0700 Subject: [PATCH] First pass at bitcoin.ros --- rosetta-cli-conf/testnet/bitcoin.ros | 402 +++++++++------------------ 1 file changed, 133 insertions(+), 269 deletions(-) diff --git a/rosetta-cli-conf/testnet/bitcoin.ros b/rosetta-cli-conf/testnet/bitcoin.ros index e9f3aa2..4092080 100644 --- a/rosetta-cli-conf/testnet/bitcoin.ros +++ b/rosetta-cli-conf/testnet/bitcoin.ros @@ -78,276 +78,140 @@ transfer(10){ }); sender_amount = 0 - {{sender.balance.value}}; - + recipient = find_balance({ + "not_account_identifier":[{{sender.account_identifier}}], + "not_coins":[{{sender.coin}}], + "minimum_balance":{ + "value": "0", + "currency": {{currency}} + }, + "create_limit": 100, + "create_probability": 50 + }); + transfer_dry_run.confirmation_depth = "1"; + transfer_dry_run.dry_run = true; + transfer_dry_run.operations = [ + { + "operation_identifier":{"index":0}, + "type":"INPUT", + "account":{{sender.account_identifier}}, + "amount":{"value":{{sender_amount}},"currency":{{currency}}}, + "coin_change":{"coin_action":"coin_spent", "coin_identifier":{{sender.coin}}} + }, + { + "operation_identifier":{"index":1}, + "type":"OUTPUT", + "account":{{recipient.account_identifier}}, + "amount":{"value":{{recipient_amount}},"currency":{{currency}}} + }, + { + "operation_identifier":{"index":2}, + "type":"OUTPUT", + "account":{{sender.account_identifier}}, + "amount":{"value":{{change_amount}},"currency":{{currency}}} + } + ]; }, transfer{ + suggested_fee = find_currency_amount({ + "currency":{{currency}}, + "amounts":{{transfer_dry_run.suggested_fee}} + }); + change_amount = {{total_change_amount}} - {{suggested_fee.value}}; + change_minus_dust = {{change_amount}} - {{dust_amount}}; + transfer.network = {{transfer_dry_run.network}}; + transfer.confirmation_depth = {{transfer_dry_run.confirmation_depth}}; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"INPUT", + "account":{{sender.account_identifier}}, + "amount":{"value":{{sender_amount}},"currency":{{currency}}}, + "coin_change":{"coin_action":"coin_spent", "coin_identifier":{{sender.coin}}} + }, + { + "operation_identifier":{"index":1}, + "type":"OUTPUT", + "account":{{recipient.account_identifier}}, + "amount":{"value":{{recipient_amount}},"currency":{{currency}}} + }, + { + "operation_identifier":{"index":2}, + "type":"OUTPUT", + "account":{{sender.account_identifier}}, + "amount":{"value":{{change_amount}},"currency":{{currency}}} + } + ]; + }, +} + +return_funds(10){ + transfer_dry_run{ + transfer_dry_run.network = {"network":"Testnet3", "blockchain":"Bitcoin"}; + currency = {"symbol":"tBTC", "decimals":8}; + + max_fee_amount = "1200"; + + // reserved_amount is max_fee_amount + min_utxo size + reserved_amount = "1800"; + sender = find_balance({ + "minimum_balance":{ + "value": {{reserved_amount}}, + "currency": {{currency}} + }, + "require_coin": true + }); + + recipient_amount = {{sender.balance.value}} - {{max_fee_amount}}; + print_message({ + "recipient_amount":{{recipient_amount}} + }); + + sender_amount = 0 - {{sender.balance.value}}; + recipient = {"address": "mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt"}; + transfer_dry_run.confirmation_depth = "1"; + transfer_dry_run.dry_run = true; + transfer_dry_run.operations = [ + { + "operation_identifier":{"index":0}, + "type":"INPUT", + "account":{{sender.account_identifier}}, + "amount":{"value":{{sender_amount}},"currency":{{currency}}}, + "coin_change":{"coin_action":"coin_spent", "coin_identifier":{{sender.coin}}} + }, + { + "operation_identifier":{"index":1}, + "type":"OUTPUT", + "account":{{recipient}}, + "amount":{"value":{{recipient_amount}},"currency":{{currency}}} + } + ]; + }, + transfer{ + suggested_fee = find_currency_amount({ + "currency":{{currency}}, + "amounts":{{transfer_dry_run.suggested_fee}} + }); + recipient_amount = {{sender.balance.value}} - {{suggested_fee.value}}; + dust_amount = "600"; + recipient_minus_dust = {{recipient_amount}} - {{dust_amount}}; + assert({{recipient_minus_dust}}); + transfer.network = {{transfer_dry_run.network}}; + transfer.confirmation_depth = {{transfer_dry_run.confirmation_depth}}; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"INPUT", + "account":{{sender.account_identifier}}, + "amount":{"value":{{sender_amount}},"currency":{{currency}}}, + "coin_change":{"coin_action":"coin_spent", "coin_identifier":{{sender.coin}}} + }, + { + "operation_identifier":{"index":1}, + "type":"OUTPUT", + "account":{{recipient}}, + "amount":{"value":{{recipient_amount}},"currency":{{currency}}} + } + ]; }, } - { - "name": "transfer", - "concurrency": 10, - "scenarios": [ - { - "name": "transfer_dry_run", - "actions": [ - { - "input": "{\"network\":\"Testnet3\", \"blockchain\":\"Bitcoin\"}", - "type": "set_variable", - "output_path": "transfer_dry_run.network" - }, - { - "input": "{\"symbol\":\"tBTC\", \"decimals\":8}", - "type": "set_variable", - "output_path": "currency" - }, - { - "input": "\"600\"", - "type": "set_variable", - "output_path": "dust_amount" - }, - { - "input": "\"1200\"", - "type": "set_variable", - "output_path": "max_fee_amount" - }, - { - "input": "{\"operation\":\"addition\", \"left_value\": {{dust_amount}}, \"right_value\": {{max_fee_amount}}}", - "type": "math", - "output_path": "send_buffer" - }, - { - "input": "\"2400\"", - "type": "set_variable", - "output_path": "reserved_amount" - }, - { - "input": "{\"require_coin\":true, \"minimum_balance\":{\"value\": {{reserved_amount}}, \"currency\": {{currency}}}}", - "type": "find_balance", - "output_path": "sender" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{sender.balance.value}}, \"right_value\": {{send_buffer}}}", - "type": "math", - "output_path": "available_amount" - }, - { - "input": "{\"minimum\": {{dust_amount}}, \"maximum\": {{available_amount}}}", - "type": "random_number", - "output_path": "recipient_amount" - }, - { - "input": "{\"recipient_amount\":{{recipient_amount}}}", - "type": "print_message" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{sender.balance.value}}, \"right_value\": {{recipient_amount}}}", - "type": "math", - "output_path": "total_change_amount" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{total_change_amount}}, \"right_value\": {{max_fee_amount}}}", - "type": "math", - "output_path": "change_amount" - }, - { - "input": "{\"change_amount\":{{change_amount}}}", - "type": "print_message" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": \"0\", \"right_value\":{{sender.balance.value}}}", - "type": "math", - "output_path": "sender_amount" - }, - { - "input": "{\"not_account_identifier\":[{{sender.account_identifier}}], \"not_coins\":[{{sender.coin}}], \"minimum_balance\":{\"value\": \"0\", \"currency\": {{currency}}}, \"create_limit\": 100, \"create_probability\": 50}", - "type": "find_balance", - "output_path": "recipient" - }, - { - "input": "\"1\"", - "type": "set_variable", - "output_path": "transfer_dry_run.confirmation_depth" - }, - { - "input": "\"true\"", - "type": "set_variable", - "output_path": "transfer_dry_run.dry_run" - }, - { - "input": "[{\"operation_identifier\":{\"index\":0},\"type\":\"INPUT\",\"account\":{{sender.account_identifier}},\"amount\":{\"value\":{{sender_amount}},\"currency\":{{currency}}}, \"coin_change\":{\"coin_action\":\"coin_spent\", \"coin_identifier\":{{sender.coin}}}},{\"operation_identifier\":{\"index\":1},\"type\":\"OUTPUT\",\"account\":{{recipient.account_identifier}},\"amount\":{\"value\":{{recipient_amount}},\"currency\":{{currency}}}}, {\"operation_identifier\":{\"index\":2},\"type\":\"OUTPUT\",\"account\":{{sender.account_identifier}},\"amount\":{\"value\":{{change_amount}},\"currency\":{{currency}}}}]", - "type": "set_variable", - "output_path": "transfer_dry_run.operations" - }, - { - "input": "{{transfer_dry_run.operations}}", - "type": "print_message" - } - ] - }, - { - "name": "transfer", - "actions": [ - { - "input": "{\"currency\":{{currency}}, \"amounts\":{{transfer_dry_run.suggested_fee}}}", - "type": "find_currency_amount", - "output_path": "suggested_fee" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{total_change_amount}}, \"right_value\": {{suggested_fee.value}}}", - "type": "math", - "output_path": "change_amount" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{change_amount}}, \"right_value\": {{dust_amount}}}", - "type": "math", - "output_path": "change_minus_dust" - }, - { - "input": "{{change_minus_dust}}", - "type": "assert" - }, - { - "input": "{\"network\":\"Testnet3\", \"blockchain\":\"Bitcoin\"}", - "type": "set_variable", - "output_path": "transfer.network" - }, - { - "input": "\"1\"", - "type": "set_variable", - "output_path": "transfer.confirmation_depth" - }, - { - "input": "[{\"operation_identifier\":{\"index\":0},\"type\":\"INPUT\",\"account\":{{sender.account_identifier}},\"amount\":{\"value\":{{sender_amount}},\"currency\":{{currency}}}, \"coin_change\":{\"coin_action\":\"coin_spent\", \"coin_identifier\":{{sender.coin}}}},{\"operation_identifier\":{\"index\":1},\"type\":\"OUTPUT\",\"account\":{{recipient.account_identifier}},\"amount\":{\"value\":{{recipient_amount}},\"currency\":{{currency}}}}, {\"operation_identifier\":{\"index\":2},\"type\":\"OUTPUT\",\"account\":{{sender.account_identifier}},\"amount\":{\"value\":{{change_amount}},\"currency\":{{currency}}}}]", - "type": "set_variable", - "output_path": "transfer.operations" - }, - { - "input": "{{transfer.operations}}", - "type": "print_message" - } - ] - } - ] - }, - { - "name": "return_funds", - "concurrency": 10, - "scenarios": [ - { - "name": "transfer_dry_run", - "actions": [ - { - "input": "{\"network\":\"Testnet3\", \"blockchain\":\"Bitcoin\"}", - "type": "set_variable", - "output_path": "transfer_dry_run.network" - }, - { - "input": "{\"symbol\":\"tBTC\", \"decimals\":8}", - "type": "set_variable", - "output_path": "currency" - }, - { - "input": "\"1200\"", - "type": "set_variable", - "output_path": "max_fee_amount" - }, - { - "input": "\"1800\"", - "type": "set_variable", - "output_path": "reserved_amount" - }, - { - "input": "{\"require_coin\":true, \"minimum_balance\":{\"value\": {{reserved_amount}}, \"currency\": {{currency}}}}", - "type": "find_balance", - "output_path": "sender" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{sender.balance.value}}, \"right_value\": {{max_fee_amount}}}", - "type": "math", - "output_path": "recipient_amount" - }, - { - "input": "{\"recipient_amount\":{{recipient_amount}}}", - "type": "print_message" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": \"0\", \"right_value\":{{sender.balance.value}}}", - "type": "math", - "output_path": "sender_amount" - }, - { - "input": "\"1\"", - "type": "set_variable", - "output_path": "transfer_dry_run.confirmation_depth" - }, - { - "input": "\"true\"", - "type": "set_variable", - "output_path": "transfer_dry_run.dry_run" - }, - { - "input": "{\"address\": \"mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt\"}", - "type": "set_variable", - "output_path": "recipient" - }, - { - "input": "[{\"operation_identifier\":{\"index\":0},\"type\":\"INPUT\",\"account\":{{sender.account_identifier}},\"amount\":{\"value\":{{sender_amount}},\"currency\":{{currency}}}, \"coin_change\":{\"coin_action\":\"coin_spent\", \"coin_identifier\":{{sender.coin}}}},{\"operation_identifier\":{\"index\":1},\"type\":\"OUTPUT\",\"account\":{{recipient}},\"amount\":{\"value\":{{recipient_amount}},\"currency\":{{currency}}}}]", - "type": "set_variable", - "output_path": "transfer_dry_run.operations" - }, - { - "input": "{{transfer_dry_run.operations}}", - "type": "print_message" - } - ] - }, - { - "name": "transfer", - "actions": [ - { - "input": "{\"currency\":{{currency}}, \"amounts\":{{transfer_dry_run.suggested_fee}}}", - "type": "find_currency_amount", - "output_path": "suggested_fee" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{sender.balance.value}}, \"right_value\": {{suggested_fee.value}}}", - "type": "math", - "output_path": "recipient_amount" - }, - { - "input": "\"600\"", - "type": "set_variable", - "output_path": "dust_amount" - }, - { - "input": "{\"operation\":\"subtraction\", \"left_value\": {{recipient_amount}}, \"right_value\": {{dust_amount}}}", - "type": "math", - "output_path": "recipient_minus_dust" - }, - { - "input": "{{recipient_minus_dust}}", - "type": "assert" - }, - { - "input": "{\"network\":\"Testnet3\", \"blockchain\":\"Bitcoin\"}", - "type": "set_variable", - "output_path": "transfer.network" - }, - { - "input": "\"1\"", - "type": "set_variable", - "output_path": "transfer.confirmation_depth" - }, - { - "input": "[{\"operation_identifier\":{\"index\":0},\"type\":\"INPUT\",\"account\":{{sender.account_identifier}},\"amount\":{\"value\":{{sender_amount}},\"currency\":{{currency}}}, \"coin_change\":{\"coin_action\":\"coin_spent\", \"coin_identifier\":{{sender.coin}}}},{\"operation_identifier\":{\"index\":1},\"type\":\"OUTPUT\",\"account\":{{recipient}},\"amount\":{\"value\":{{recipient_amount}},\"currency\":{{currency}}}}]", - "type": "set_variable", - "output_path": "transfer.operations" - }, - { - "input": "{{transfer.operations}}", - "type": "print_message" - } - ] - } - ] - }