xgt-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +56 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +45 -0
  10. data/Rakefile +6 -0
  11. data/bin/.wallet.swp +0 -0
  12. data/bin/setup +8 -0
  13. data/bin/wallet +438 -0
  14. data/examples/api/account_by_key_api/get_key_references.rb +18 -0
  15. data/examples/api/account_history_api/deprecated/enum_virtual_ops.rb +15 -0
  16. data/examples/api/account_history_api/deprecated/get_transaction.rb +12 -0
  17. data/examples/api/account_history_api/get_account_history.rb +16 -0
  18. data/examples/api/account_history_api/get_ops_in_block.rb +17 -0
  19. data/examples/api/chain_api/deprecated/dummy_code.rb +65 -0
  20. data/examples/api/chain_api/deprecated/push_block.rb +20 -0
  21. data/examples/api/database_api/accounts/find_accounts.rb +16 -0
  22. data/examples/api/database_api/accounts/list_accounts.rb +18 -0
  23. data/examples/api/database_api/accounts/not_supported/find_account_recovery_requests.rb +16 -0
  24. data/examples/api/database_api/accounts/not_supported/find_change_recovery_account_requests.rb +0 -0
  25. data/examples/api/database_api/accounts/not_supported/find_decline_voting_rights_requests.rb +0 -0
  26. data/examples/api/database_api/accounts/not_supported/find_escrows.rb +0 -0
  27. data/examples/api/database_api/accounts/not_supported/find_sbd_conversion_requests.rb +0 -0
  28. data/examples/api/database_api/accounts/not_supported/find_vesting_delegation_expirations.rb +0 -0
  29. data/examples/api/database_api/accounts/not_supported/find_vesting_delegations.rb +0 -0
  30. data/examples/api/database_api/accounts/not_supported/find_withdraw_vesting_routes.rb +18 -0
  31. data/examples/api/database_api/accounts/not_supported/list_account_recovery_requests.rb +18 -0
  32. data/examples/api/database_api/accounts/not_supported/list_change_recovery_account_requests.rb +0 -0
  33. data/examples/api/database_api/accounts/not_supported/list_decline_voting_rights_requests.rb +0 -0
  34. data/examples/api/database_api/accounts/not_supported/list_escrows.rb +18 -0
  35. data/examples/api/database_api/accounts/not_supported/list_recovery_histories.rb +17 -0
  36. data/examples/api/database_api/accounts/not_supported/list_sbd_conversion_requests.rb +0 -0
  37. data/examples/api/database_api/accounts/not_supported/list_vesting_delegation_expirations.rb +0 -0
  38. data/examples/api/database_api/accounts/not_supported/list_vesting_delegations.rb +18 -0
  39. data/examples/api/database_api/accounts/not_supported/list_withdraw_vesting_routes.rb +18 -0
  40. data/examples/api/database_api/authority/not_supported/find_smt_contributions.rb +0 -0
  41. data/examples/api/database_api/authority/not_supported/find_smt_token_balances.rb +0 -0
  42. data/examples/api/database_api/authority/not_supported/find_smt_token_emissions.rb +0 -0
  43. data/examples/api/database_api/authority/not_supported/find_smt_tokens.rb +0 -0
  44. data/examples/api/database_api/authority/not_supported/get_nai_pool.rb +0 -0
  45. data/examples/api/database_api/authority/not_supported/get_potential_signatures.rb +0 -0
  46. data/examples/api/database_api/authority/not_supported/get_required_signatures.rb +0 -0
  47. data/examples/api/database_api/authority/not_supported/get_smt_balances.rb +0 -0
  48. data/examples/api/database_api/authority/not_supported/get_transaction_hex.rb +0 -0
  49. data/examples/api/database_api/authority/not_supported/list_smt_contributions.rb +0 -0
  50. data/examples/api/database_api/authority/not_supported/list_smt_token_balances.rb +0 -0
  51. data/examples/api/database_api/authority/not_supported/list_smt_token_emissions.rb +0 -0
  52. data/examples/api/database_api/authority/not_supported/list_smt_tokens.rb +0 -0
  53. data/examples/api/database_api/authority/not_supported/verify_account_authority.rb +0 -0
  54. data/examples/api/database_api/authority/not_supported/verify_authority.rb +0 -0
  55. data/examples/api/database_api/authority/not_supported/verify_signatures.rb +0 -0
  56. data/examples/api/database_api/comments/not_supported/find_comments.rb +0 -0
  57. data/examples/api/database_api/comments/not_supported/find_votes.rb +0 -0
  58. data/examples/api/database_api/comments/not_supported/list_comments.rb +0 -0
  59. data/examples/api/database_api/comments/not_supported/list_votes.rb +0 -0
  60. data/examples/api/database_api/globals/get_config.rb +14 -0
  61. data/examples/api/database_api/globals/get_dynamic_global_properties.rb +14 -0
  62. data/examples/api/database_api/globals/get_hardfork_properties.rb +14 -0
  63. data/examples/api/database_api/globals/get_reward_funds.rb +14 -0
  64. data/examples/api/database_api/globals/get_version.rb +15 -0
  65. data/examples/api/database_api/globals/get_witness_schedule.rb +14 -0
  66. data/examples/api/database_api/market/not_supported/find_limit_orders.rb +0 -0
  67. data/examples/api/database_api/market/not_supported/get_order_book.rb +0 -0
  68. data/examples/api/database_api/market/not_supported/list_limit_orders.rb +0 -0
  69. data/examples/api/database_api/sps/not_supported/find_proposals.rb +0 -0
  70. data/examples/api/database_api/sps/not_supported/list_proposal_votes.rb +0 -0
  71. data/examples/api/database_api/sps/not_supported/list_proposals.rb +0 -0
  72. data/examples/api/database_api/witnesses/deprecated/get_round.rb +14 -0
  73. data/examples/api/database_api/witnesses/find_witnesses.rb +16 -0
  74. data/examples/api/database_api/witnesses/get_active_witnesses.rb +14 -0
  75. data/examples/api/database_api/witnesses/list_witnesses.rb +17 -0
  76. data/examples/api/database_api/witnesses/not_supported/list_witness_votes.rb +16 -0
  77. data/examples/api/extras/get_balance.rb +27 -0
  78. data/examples/api/network_broadcast_api/broadcast_transaction.rb +16 -0
  79. data/examples/api/network_broadcast_api/broadcast_transaction_synchronous.rb +15 -0
  80. data/examples/api/network_broadcast_api/create_wallet.rb +79 -0
  81. data/examples/api/network_broadcast_api/dummy_code.rb +68 -0
  82. data/examples/api/network_broadcast_api/get_transaction_hex.rb +17 -0
  83. data/examples/api/network_broadcast_api/not_supported/broadcast_block.rb +17 -0
  84. data/examples/api/network_broadcast_api/transfer.rb +45 -0
  85. data/examples/api/payloads.txt +3580 -0
  86. data/examples/api/transaction_status_api/find_transaction.rb +16 -0
  87. data/examples/operations/broadcast_transaction_synchronous.rb +16 -0
  88. data/examples/operations/completed/account_create.rb +79 -0
  89. data/examples/operations/completed/account_witness_proxy.rb +29 -0
  90. data/examples/operations/completed/account_witness_vote.rb +31 -0
  91. data/examples/operations/completed/claim_account.rb +33 -0
  92. data/examples/operations/completed/create_claimed_account.rb +62 -0
  93. data/examples/operations/completed/custom.rb +31 -0
  94. data/examples/operations/completed/custom_json.rb +32 -0
  95. data/examples/operations/completed/decline_voting_rights.rb +30 -0
  96. data/examples/operations/completed/delegate_some_vesting_shares.rb +32 -0
  97. data/examples/operations/completed/set_withdraw_vesting_route.rb +32 -0
  98. data/examples/operations/completed/transfer.rb +44 -0
  99. data/examples/operations/completed/transfer_to_vesting.rb +32 -0
  100. data/examples/operations/completed/update_proposal_votes.rb +31 -0
  101. data/examples/operations/completed/withdraw_vesting.rb +30 -0
  102. data/examples/operations/completed/witness_update.rb +64 -0
  103. data/examples/operations/deprecated/account_update.rb +44 -0
  104. data/examples/operations/deprecated/cancel_transfer_from_savings.rb +30 -0
  105. data/examples/operations/deprecated/challenge_authority.rb +28 -0
  106. data/examples/operations/deprecated/claim_reward_balance.rb +35 -0
  107. data/examples/operations/deprecated/convert.rb +38 -0
  108. data/examples/operations/deprecated/custom_binary.rb +31 -0
  109. data/examples/operations/deprecated/feed_publish.rb +33 -0
  110. data/examples/operations/do_later/change_recovery_account.rb +31 -0
  111. data/examples/operations/do_later/claim_reward_balance2.rb +37 -0
  112. data/examples/operations/do_later/remove_proposal_votes.rb +0 -0
  113. data/examples/operations/in_progress/create_proposal.rb +40 -0
  114. data/examples/operations/in_progress/escrow_approve.rb +36 -0
  115. data/examples/operations/in_progress/witness_set_properties.rb +62 -0
  116. data/lib/xgt/.ruby.rb.swp +0 -0
  117. data/lib/xgt/ruby.rb +200 -0
  118. data/lib/xgt/ruby/version.rb +5 -0
  119. data/payloads.txt +461 -0
  120. data/sample.rb +41 -0
  121. data/sample2.rb +104 -0
  122. data/xgt-ruby.gemspec +31 -0
  123. metadata +262 -0
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def get_key_references(keys)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ keys: keys
7
+ }
8
+ response = rpc.call('account_by_key_api.get_key_references', payload)
9
+
10
+ puts JSON.pretty_generate(payload)
11
+ puts "\n\n"
12
+ puts JSON.pretty_generate(response)
13
+ response
14
+ end
15
+
16
+ keys = ['XGT799RiXcTe1kKm1TRiAqaGySaH7oh3J34YYB4h31zw3df3P6ei5', 'XGT74zqjh1D6S8LRjYiHEFdQ228k4qhgoTY1bmEu8BZBUUd5wsL6n']
17
+
18
+ get_key_references(keys)
@@ -0,0 +1,15 @@
1
+ require 'xgt/ruby'
2
+
3
+ def enum_virtual_ops(block_begin, block_end)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ 'block_range_begin' => block_begin,
7
+ 'block_range_end' => block_end
8
+ }
9
+ rpc.call('account_history_api.enum_virtual_ops', payload)
10
+ end
11
+
12
+ ops = enum_virtual_ops('1', '500')
13
+
14
+ puts JSON.pretty_generate(ops)
15
+
@@ -0,0 +1,12 @@
1
+ require 'xgt/ruby'
2
+
3
+ def get_transaction(tx_id)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ 'tx_id' => tx_id
7
+ }
8
+ rpc.call('account_history_api.get_transaction', payload)
9
+ end
10
+
11
+ tx = get_transaction('535268f92daf01be6bfdeb79be5ef67bc6210a30')
12
+ puts JSON.pretty_generate(tx)
@@ -0,0 +1,16 @@
1
+ require 'xgt/ruby'
2
+
3
+ def get_account_history(address)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ account: address
7
+ }
8
+ response = rpc.call('account_history_api.get_account_history', payload)
9
+
10
+ puts JSON.pretty_generate(payload)
11
+ puts "\n\n"
12
+ puts JSON.pretty_generate(response)
13
+ response
14
+ end
15
+
16
+ get_account_history('XGT22auyHoY4yZPU')
@@ -0,0 +1,17 @@
1
+ require 'xgt/ruby'
2
+
3
+ def get_ops_in_block(block_num)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ block_num: block_num,
7
+ only_virtual: false
8
+ }
9
+ response = rpc.call('account_history_api.get_ops_in_block', payload)
10
+
11
+ puts JSON.pretty_generate(payload)
12
+ puts "\n\n"
13
+ puts JSON.pretty_generate(response)
14
+ response
15
+ end
16
+
17
+ get_ops_in_block('234')
@@ -0,0 +1,65 @@
1
+ require 'xgt/ruby'
2
+
3
+ # Requires local node: clone into xgt repo, rake run
4
+
5
+ module Dummy_code
6
+
7
+ def Dummy_code.account_create()
8
+ current_name = ENV["NAME"] || "XGT0000000000000"
9
+ wif = ENV["WIF"] || '5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n'
10
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
11
+ config = rpc.call('database_api.get_config', {})
12
+ address_prefix = config['XGT_ADDRESS_PREFIX']
13
+ chain_id = config["XGT_CHAIN_ID"]
14
+
15
+ witness_schedule = rpc.call('database_api.get_witness_schedule', {}) || {}
16
+ chain_properties = witness_schedule['median_props']
17
+
18
+ fee = chain_properties["account_creation_fee"] || {}
19
+ amount = fee['amount'].to_f * 0.001
20
+ creation_fee = "#{'%0.3f' % amount} XGT"
21
+
22
+ # Generate keys
23
+ master = Xgt::Ruby::Auth.random_wif
24
+ recovery_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'recovery')
25
+ recovery_public = Xgt::Ruby::Auth.wif_to_public_key(recovery_private, address_prefix)
26
+ money_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'money')
27
+ money_public = Xgt::Ruby::Auth.wif_to_public_key(money_private, address_prefix)
28
+ social_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'social')
29
+ social_public = Xgt::Ruby::Auth.wif_to_public_key(social_private, address_prefix)
30
+ memo_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'memo')
31
+ memo_public = Xgt::Ruby::Auth.wif_to_public_key(memo_private, address_prefix)
32
+
33
+ txn = {
34
+ 'extensions' => [],
35
+ 'operations' => [[
36
+ 'account_create',
37
+ {
38
+ 'fee' => creation_fee,
39
+ 'creator' => current_name,
40
+ 'recovery' => {
41
+ 'weight_threshold' => 1,
42
+ 'account_auths' => [],
43
+ 'key_auths' => [[recovery_public, 1]]
44
+ },
45
+ 'money' => {
46
+ 'weight_threshold' => 1,
47
+ 'account_auths' => [],
48
+ 'key_auths' => [[money_public, 1]]
49
+ },
50
+ 'social' => {
51
+ 'weight_threshold' => 1,
52
+ 'account_auths' => [],
53
+ 'key_auths' => [[social_public, 1]]
54
+ },
55
+ 'memo_key' => memo_public,
56
+ 'json_metadata' => "",
57
+ 'extensions' => []
58
+ }
59
+ ]]
60
+ }
61
+
62
+ signed = Xgt::Ruby::Auth.sign_transaction(rpc, txn, [wif], chain_id)
63
+ signed
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ require 'xgt/ruby'
2
+ load 'dummy_code.rb'
3
+
4
+ def push_block(signed_transaction)
5
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
6
+ payload = {
7
+ signed_block: signed_transaction
8
+ }
9
+ response = rpc.call('chain_api.push_block', payload)
10
+
11
+ puts JSON.pretty_generate(payload)
12
+ puts "\n\n"
13
+ puts JSON.pretty_generate(response)
14
+ response
15
+ end
16
+
17
+ push_block(Dummy_code.account_create())
18
+
19
+
20
+
@@ -0,0 +1,16 @@
1
+ require 'xgt/ruby'
2
+
3
+ def find_accounts(wallet_addresses)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ accounts: wallet_addresses
7
+ }
8
+ response = rpc.call('database_api.find_accounts', payload)
9
+
10
+ puts JSON.pretty_generate(payload)
11
+ puts "\n\n"
12
+ puts JSON.pretty_generate(response)
13
+ response
14
+ end
15
+
16
+ find_accounts(['XGT22auyHoY4yZPU', 'XGT2y6XQetmSbn3H'])
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def list_accounts
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: 0,
7
+ limit: 5,
8
+ order: "by_name"
9
+ }
10
+ response = rpc.call('database_api.list_accounts', payload)
11
+
12
+ puts JSON.pretty_generate(payload)
13
+ puts "\n\n"
14
+ puts JSON.pretty_generate(response)
15
+ response
16
+ end
17
+
18
+ list_accounts
@@ -0,0 +1,16 @@
1
+ require 'xgt/ruby'
2
+
3
+ def find_account_recovery_requests(accounts)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ accounts: [accounts]
7
+ }
8
+ response = rpc.call('database_api.find_account_recovery_requests', payload)
9
+
10
+ puts JSON.pretty_generate(payload)
11
+ puts "\n\n"
12
+ puts JSON.pretty_generate(response)
13
+ response
14
+ end
15
+
16
+ find_account_recovery_requests('XGT0000000000000')
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def find_withdraw_vesting_routes(routes)
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: [],
7
+ limit: 1,
8
+ order: 'by_withdraw_route'
9
+ }
10
+ response = rpc.call('database_api.find_withdraw_vesting_routes', payload)
11
+
12
+ puts JSON.pretty_generate(payload)
13
+ puts "\n\n"
14
+ puts JSON.pretty_generate(response)
15
+ response
16
+ end
17
+
18
+ find_withdraw_vesting_routes('')
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def list_account_recovery_requests
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: '',
7
+ limit: 1,
8
+ order: 'by_account'
9
+ }
10
+ response = rpc.call('database_api.list_account_recovery_requests', payload)
11
+
12
+ puts JSON.pretty_generate(payload)
13
+ puts "\n\n"
14
+ puts JSON.pretty_generate(response)
15
+ response
16
+ end
17
+
18
+ list_account_recovery_requests
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def list_escrows
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: ["XGT0000000000000", 0],
7
+ limit: 1,
8
+ order: 'by_from_id'
9
+ }
10
+ response = rpc.call('database_api.list_escrows', payload)
11
+
12
+ puts JSON.pretty_generate(payload)
13
+ puts "\n\n"
14
+ puts JSON.pretty_generate(response)
15
+ response
16
+ end
17
+
18
+ list_escrows
@@ -0,0 +1,17 @@
1
+ require 'xgt/ruby'
2
+
3
+ def list_recovery_histories
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: [],
7
+ limit: 1
8
+ }
9
+ response = rpc.call('database_api.list_recovery_histories', payload)
10
+
11
+ puts JSON.pretty_generate(payload)
12
+ puts "\n\n"
13
+ puts JSON.pretty_generate(response)
14
+ response
15
+ end
16
+
17
+ list_recovery_histories
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def list_vesting_delegations
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: [],
7
+ limit: 1,
8
+ order: 'by_delegation'
9
+ }
10
+ response = rpc.call('database_api.list_vesting_delegations', payload)
11
+
12
+ puts JSON.pretty_generate(payload)
13
+ puts "\n\n"
14
+ puts JSON.pretty_generate(response)
15
+ response
16
+ end
17
+
18
+ list_vesting_delegations
@@ -0,0 +1,18 @@
1
+ require 'xgt/ruby'
2
+
3
+ def list_withdraw_vesting_routes
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {
6
+ start: [],
7
+ limit: 1,
8
+ order: 'by_withdraw_route'
9
+ }
10
+ response = rpc.call('database_api.list_withdraw_vesting_routes', payload)
11
+
12
+ puts JSON.pretty_generate(payload)
13
+ "\n\n"
14
+ puts JSON.pretty_generate(response)
15
+ response
16
+ end
17
+
18
+ list_withdraw_vesting_routes
@@ -0,0 +1,14 @@
1
+ require 'xgt/ruby'
2
+
3
+ def get_config
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {}
6
+ response = rpc.call('database_api.get_config', payload)
7
+
8
+ puts JSON.pretty_generate(payload)
9
+ puts "\n\n"
10
+ puts JSON.pretty_generate(response)
11
+ response
12
+ end
13
+
14
+ get_config
@@ -0,0 +1,14 @@
1
+ require 'xgt/ruby'
2
+
3
+ def get_dynamic_global_properties
4
+ rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
5
+ payload = {}
6
+ response = rpc.call('database_api.get_dynamic_global_properties', payload)
7
+
8
+ puts JSON.pretty_generate(payload)
9
+ puts "\n\n"
10
+ puts JSON.pretty_generate(response)
11
+ response
12
+ end
13
+
14
+ get_dynamic_global_properties