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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/bin/.wallet.swp +0 -0
- data/bin/setup +8 -0
- data/bin/wallet +438 -0
- data/examples/api/account_by_key_api/get_key_references.rb +18 -0
- data/examples/api/account_history_api/deprecated/enum_virtual_ops.rb +15 -0
- data/examples/api/account_history_api/deprecated/get_transaction.rb +12 -0
- data/examples/api/account_history_api/get_account_history.rb +16 -0
- data/examples/api/account_history_api/get_ops_in_block.rb +17 -0
- data/examples/api/chain_api/deprecated/dummy_code.rb +65 -0
- data/examples/api/chain_api/deprecated/push_block.rb +20 -0
- data/examples/api/database_api/accounts/find_accounts.rb +16 -0
- data/examples/api/database_api/accounts/list_accounts.rb +18 -0
- data/examples/api/database_api/accounts/not_supported/find_account_recovery_requests.rb +16 -0
- data/examples/api/database_api/accounts/not_supported/find_change_recovery_account_requests.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/find_decline_voting_rights_requests.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/find_escrows.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/find_sbd_conversion_requests.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/find_vesting_delegation_expirations.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/find_vesting_delegations.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/find_withdraw_vesting_routes.rb +18 -0
- data/examples/api/database_api/accounts/not_supported/list_account_recovery_requests.rb +18 -0
- data/examples/api/database_api/accounts/not_supported/list_change_recovery_account_requests.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/list_decline_voting_rights_requests.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/list_escrows.rb +18 -0
- data/examples/api/database_api/accounts/not_supported/list_recovery_histories.rb +17 -0
- data/examples/api/database_api/accounts/not_supported/list_sbd_conversion_requests.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/list_vesting_delegation_expirations.rb +0 -0
- data/examples/api/database_api/accounts/not_supported/list_vesting_delegations.rb +18 -0
- data/examples/api/database_api/accounts/not_supported/list_withdraw_vesting_routes.rb +18 -0
- data/examples/api/database_api/authority/not_supported/find_smt_contributions.rb +0 -0
- data/examples/api/database_api/authority/not_supported/find_smt_token_balances.rb +0 -0
- data/examples/api/database_api/authority/not_supported/find_smt_token_emissions.rb +0 -0
- data/examples/api/database_api/authority/not_supported/find_smt_tokens.rb +0 -0
- data/examples/api/database_api/authority/not_supported/get_nai_pool.rb +0 -0
- data/examples/api/database_api/authority/not_supported/get_potential_signatures.rb +0 -0
- data/examples/api/database_api/authority/not_supported/get_required_signatures.rb +0 -0
- data/examples/api/database_api/authority/not_supported/get_smt_balances.rb +0 -0
- data/examples/api/database_api/authority/not_supported/get_transaction_hex.rb +0 -0
- data/examples/api/database_api/authority/not_supported/list_smt_contributions.rb +0 -0
- data/examples/api/database_api/authority/not_supported/list_smt_token_balances.rb +0 -0
- data/examples/api/database_api/authority/not_supported/list_smt_token_emissions.rb +0 -0
- data/examples/api/database_api/authority/not_supported/list_smt_tokens.rb +0 -0
- data/examples/api/database_api/authority/not_supported/verify_account_authority.rb +0 -0
- data/examples/api/database_api/authority/not_supported/verify_authority.rb +0 -0
- data/examples/api/database_api/authority/not_supported/verify_signatures.rb +0 -0
- data/examples/api/database_api/comments/not_supported/find_comments.rb +0 -0
- data/examples/api/database_api/comments/not_supported/find_votes.rb +0 -0
- data/examples/api/database_api/comments/not_supported/list_comments.rb +0 -0
- data/examples/api/database_api/comments/not_supported/list_votes.rb +0 -0
- data/examples/api/database_api/globals/get_config.rb +14 -0
- data/examples/api/database_api/globals/get_dynamic_global_properties.rb +14 -0
- data/examples/api/database_api/globals/get_hardfork_properties.rb +14 -0
- data/examples/api/database_api/globals/get_reward_funds.rb +14 -0
- data/examples/api/database_api/globals/get_version.rb +15 -0
- data/examples/api/database_api/globals/get_witness_schedule.rb +14 -0
- data/examples/api/database_api/market/not_supported/find_limit_orders.rb +0 -0
- data/examples/api/database_api/market/not_supported/get_order_book.rb +0 -0
- data/examples/api/database_api/market/not_supported/list_limit_orders.rb +0 -0
- data/examples/api/database_api/sps/not_supported/find_proposals.rb +0 -0
- data/examples/api/database_api/sps/not_supported/list_proposal_votes.rb +0 -0
- data/examples/api/database_api/sps/not_supported/list_proposals.rb +0 -0
- data/examples/api/database_api/witnesses/deprecated/get_round.rb +14 -0
- data/examples/api/database_api/witnesses/find_witnesses.rb +16 -0
- data/examples/api/database_api/witnesses/get_active_witnesses.rb +14 -0
- data/examples/api/database_api/witnesses/list_witnesses.rb +17 -0
- data/examples/api/database_api/witnesses/not_supported/list_witness_votes.rb +16 -0
- data/examples/api/extras/get_balance.rb +27 -0
- data/examples/api/network_broadcast_api/broadcast_transaction.rb +16 -0
- data/examples/api/network_broadcast_api/broadcast_transaction_synchronous.rb +15 -0
- data/examples/api/network_broadcast_api/create_wallet.rb +79 -0
- data/examples/api/network_broadcast_api/dummy_code.rb +68 -0
- data/examples/api/network_broadcast_api/get_transaction_hex.rb +17 -0
- data/examples/api/network_broadcast_api/not_supported/broadcast_block.rb +17 -0
- data/examples/api/network_broadcast_api/transfer.rb +45 -0
- data/examples/api/payloads.txt +3580 -0
- data/examples/api/transaction_status_api/find_transaction.rb +16 -0
- data/examples/operations/broadcast_transaction_synchronous.rb +16 -0
- data/examples/operations/completed/account_create.rb +79 -0
- data/examples/operations/completed/account_witness_proxy.rb +29 -0
- data/examples/operations/completed/account_witness_vote.rb +31 -0
- data/examples/operations/completed/claim_account.rb +33 -0
- data/examples/operations/completed/create_claimed_account.rb +62 -0
- data/examples/operations/completed/custom.rb +31 -0
- data/examples/operations/completed/custom_json.rb +32 -0
- data/examples/operations/completed/decline_voting_rights.rb +30 -0
- data/examples/operations/completed/delegate_some_vesting_shares.rb +32 -0
- data/examples/operations/completed/set_withdraw_vesting_route.rb +32 -0
- data/examples/operations/completed/transfer.rb +44 -0
- data/examples/operations/completed/transfer_to_vesting.rb +32 -0
- data/examples/operations/completed/update_proposal_votes.rb +31 -0
- data/examples/operations/completed/withdraw_vesting.rb +30 -0
- data/examples/operations/completed/witness_update.rb +64 -0
- data/examples/operations/deprecated/account_update.rb +44 -0
- data/examples/operations/deprecated/cancel_transfer_from_savings.rb +30 -0
- data/examples/operations/deprecated/challenge_authority.rb +28 -0
- data/examples/operations/deprecated/claim_reward_balance.rb +35 -0
- data/examples/operations/deprecated/convert.rb +38 -0
- data/examples/operations/deprecated/custom_binary.rb +31 -0
- data/examples/operations/deprecated/feed_publish.rb +33 -0
- data/examples/operations/do_later/change_recovery_account.rb +31 -0
- data/examples/operations/do_later/claim_reward_balance2.rb +37 -0
- data/examples/operations/do_later/remove_proposal_votes.rb +0 -0
- data/examples/operations/in_progress/create_proposal.rb +40 -0
- data/examples/operations/in_progress/escrow_approve.rb +36 -0
- data/examples/operations/in_progress/witness_set_properties.rb +62 -0
- data/lib/xgt/.ruby.rb.swp +0 -0
- data/lib/xgt/ruby.rb +200 -0
- data/lib/xgt/ruby/version.rb +5 -0
- data/payloads.txt +461 -0
- data/sample.rb +41 -0
- data/sample2.rb +104 -0
- data/xgt-ruby.gemspec +31 -0
- metadata +262 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_hardfork_properties
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {}
|
|
6
|
+
response = rpc.call('database_api.get_hardfork_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_hardfork_properties
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_reward_funds
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {}
|
|
6
|
+
response = rpc.call('database_api.get_reward_funds', 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_reward_funds
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_version
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {}
|
|
6
|
+
response = rpc.call('database_api.get_version', 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_version
|
|
15
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_witness_schedule
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {}
|
|
6
|
+
response = rpc.call('database_api.get_witness_schedule', 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_witness_schedule
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_round
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {}
|
|
6
|
+
response = rpc.call('database_api.get_round', 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_round
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def find_witnesses(witnesses)
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {
|
|
6
|
+
recoveries: [witnesses],
|
|
7
|
+
}
|
|
8
|
+
response = rpc.call('database_api.find_witnesses', 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_witnesses('XGT0000000000000')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_active_witnesses
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {}
|
|
6
|
+
response = rpc.call('database_api.get_active_witnesses', 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_active_witnesses
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def list_witnesses
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
payload = {
|
|
6
|
+
start: 0,
|
|
7
|
+
limit: 1,
|
|
8
|
+
order: "by_name"
|
|
9
|
+
}
|
|
10
|
+
response = rpc.call('database_api.list_witnesses', payload)
|
|
11
|
+
puts JSON.pretty_generate(payload)
|
|
12
|
+
puts "\n\n"
|
|
13
|
+
puts JSON.pretty_generate(response)
|
|
14
|
+
response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
list_witnesses
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def list_witness_votes
|
|
4
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
5
|
+
wif = '5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n'
|
|
6
|
+
config = rpc.call('database_api.get_config', {})
|
|
7
|
+
address_prefix = config['XGT_ADDRESS_PREFIX']
|
|
8
|
+
chain_id = config["XGT_CHAIN_ID"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
signed = Xgt::Ruby::Auth.sign_transaction(rpc, txn, [wif], chain_id)
|
|
12
|
+
puts JSON.pretty_generate(signed)
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
list_witness_votes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def get_balance(name)
|
|
4
|
+
|
|
5
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
6
|
+
config = rpc.call('database_api.get_config', {})
|
|
7
|
+
chain_id = config['XGT_CHAIN_ID']
|
|
8
|
+
witness_schedule = rpc.call('database_api.get_witness_schedule', {}) || {}
|
|
9
|
+
chain_properties = witness_schedule['median_props']
|
|
10
|
+
fee = chain_properties['account_creation_fee'] || {}
|
|
11
|
+
amount = fee['amount'].to_f * 0.001
|
|
12
|
+
creation_fee = "#{'%0.3f' % amount} XGT"
|
|
13
|
+
currency_symbol = creation_fee.split(/\s+/).last
|
|
14
|
+
account = rpc.call('database_api.find_accounts', { 'accounts' => [name] })
|
|
15
|
+
|
|
16
|
+
raw_balance = account['accounts'].first['balance']['amount'].to_i
|
|
17
|
+
balance = '%.3f' % (raw_balance * 0.001)
|
|
18
|
+
string_balance = %(#{balance} #{currency_symbol})
|
|
19
|
+
|
|
20
|
+
puts JSON.pretty_generate(string_balance)
|
|
21
|
+
puts "\n\n"
|
|
22
|
+
puts JSON.pretty_generate(account)
|
|
23
|
+
account
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
get_balance('XGT2xtVNz7nxdDp6')
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
load 'dummy_code.rb'
|
|
3
|
+
|
|
4
|
+
def broadcast_transaction(signed_transaction)
|
|
5
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
6
|
+
payload = [signed_transaction]
|
|
7
|
+
response = rpc.call('network_broadcast_api.broadcast_transaction', payload)
|
|
8
|
+
|
|
9
|
+
puts JSON.pretty_generate(payload)
|
|
10
|
+
puts "\n\n"
|
|
11
|
+
puts JSON.pretty_generate(response)
|
|
12
|
+
# Returns nothing
|
|
13
|
+
response
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
broadcast_transaction(Dummy_code.account_create())
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
load 'dummy_code.rb'
|
|
3
|
+
|
|
4
|
+
def broadcast_transaction_synchronous(signed_transaction)
|
|
5
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
6
|
+
payload = [signed_transaction]
|
|
7
|
+
response = rpc.call('network_broadcast_api.broadcast_transaction_synchronous', payload)
|
|
8
|
+
|
|
9
|
+
puts JSON.pretty_generate(payload)
|
|
10
|
+
puts "\n\n"
|
|
11
|
+
puts JSON.pretty_generate(response)
|
|
12
|
+
response
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
broadcast_transaction_synchronous(Dummy_code.account_create())
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
# Requires local node: clone into xgt repo, rake run
|
|
4
|
+
|
|
5
|
+
def account_create()
|
|
6
|
+
current_name = ENV["NAME"] || "XGT0000000000000"
|
|
7
|
+
wif = ENV["WIF"] || '5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n'
|
|
8
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
9
|
+
config = rpc.call('database_api.get_config', {})
|
|
10
|
+
address_prefix = config['XGT_ADDRESS_PREFIX']
|
|
11
|
+
chain_id = config["XGT_CHAIN_ID"]
|
|
12
|
+
|
|
13
|
+
witness_schedule = rpc.call('database_api.get_witness_schedule', {}) || {}
|
|
14
|
+
chain_properties = witness_schedule['median_props']
|
|
15
|
+
|
|
16
|
+
fee = chain_properties["account_creation_fee"] || {}
|
|
17
|
+
amount = fee['amount'].to_f * 0.001
|
|
18
|
+
creation_fee = "#{'%0.3f' % amount} XGT"
|
|
19
|
+
|
|
20
|
+
# Generate keys
|
|
21
|
+
master = Xgt::Ruby::Auth.random_wif
|
|
22
|
+
recovery_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'recovery')
|
|
23
|
+
recovery_public = Xgt::Ruby::Auth.wif_to_public_key(recovery_private, address_prefix)
|
|
24
|
+
money_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'money')
|
|
25
|
+
money_public = Xgt::Ruby::Auth.wif_to_public_key(money_private, address_prefix)
|
|
26
|
+
social_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'social')
|
|
27
|
+
social_public = Xgt::Ruby::Auth.wif_to_public_key(social_private, address_prefix)
|
|
28
|
+
memo_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'memo')
|
|
29
|
+
memo_public = Xgt::Ruby::Auth.wif_to_public_key(memo_private, address_prefix)
|
|
30
|
+
|
|
31
|
+
puts JSON.pretty_generate(recovery_private)
|
|
32
|
+
puts "\n\n"
|
|
33
|
+
puts JSON.pretty_generate(money_private)
|
|
34
|
+
puts "\n\n"
|
|
35
|
+
|
|
36
|
+
txn = {
|
|
37
|
+
'extensions': [],
|
|
38
|
+
'operations': [[
|
|
39
|
+
'account_create',
|
|
40
|
+
{
|
|
41
|
+
'fee': creation_fee,
|
|
42
|
+
'creator': current_name,
|
|
43
|
+
'recovery': {
|
|
44
|
+
'weight_threshold': 1,
|
|
45
|
+
'account_auths': [],
|
|
46
|
+
'key_auths': [[recovery_public, 1]]
|
|
47
|
+
},
|
|
48
|
+
'money': {
|
|
49
|
+
'weight_threshold': 1,
|
|
50
|
+
'account_auths': [],
|
|
51
|
+
'key_auths': [[money_public, 1]]
|
|
52
|
+
},
|
|
53
|
+
'social': {
|
|
54
|
+
'weight_threshold': 1,
|
|
55
|
+
'account_auths': [],
|
|
56
|
+
'key_auths': [[social_public, 1]]
|
|
57
|
+
},
|
|
58
|
+
'memo_key': memo_public,
|
|
59
|
+
'json_metadata': "",
|
|
60
|
+
'extensions': []
|
|
61
|
+
}
|
|
62
|
+
]]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
puts "\e[36mSent:\n\e[0m"
|
|
66
|
+
puts JSON.pretty_generate(txn)
|
|
67
|
+
signed = Xgt::Ruby::Auth.sign_transaction(rpc, txn, [wif], chain_id)
|
|
68
|
+
response = rpc.call('network_broadcast_api.broadcast_transaction_synchronous', [signed])
|
|
69
|
+
puts "\e[36m\nResponse:\n\e[0m"
|
|
70
|
+
puts JSON.pretty_generate(response)
|
|
71
|
+
|
|
72
|
+
account_names = rpc.call('condenser_api.get_account_names_by_block_num', [response['block_num']])
|
|
73
|
+
account_name = account_names.first
|
|
74
|
+
|
|
75
|
+
puts("\nAccount name: #{account_name}")
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
account_create()
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
|
|
9
|
+
current_name = ENV["NAME"] || "XGT0000000000000"
|
|
10
|
+
wif = ENV["WIF"] || '5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n'
|
|
11
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
12
|
+
config = rpc.call('database_api.get_config', {})
|
|
13
|
+
address_prefix = config['XGT_ADDRESS_PREFIX']
|
|
14
|
+
chain_id = config["XGT_CHAIN_ID"]
|
|
15
|
+
|
|
16
|
+
witness_schedule = rpc.call('database_api.get_witness_schedule', {}) || {}
|
|
17
|
+
chain_properties = witness_schedule['median_props']
|
|
18
|
+
|
|
19
|
+
fee = chain_properties["account_creation_fee"] || {}
|
|
20
|
+
amount = fee['amount'].to_f * 0.001
|
|
21
|
+
creation_fee = "#{'%0.3f' % amount} XGT"
|
|
22
|
+
|
|
23
|
+
# Generate keys
|
|
24
|
+
master = Xgt::Ruby::Auth.random_wif
|
|
25
|
+
recovery_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'recovery')
|
|
26
|
+
recovery_public = Xgt::Ruby::Auth.wif_to_public_key(recovery_private, address_prefix)
|
|
27
|
+
money_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'money')
|
|
28
|
+
money_public = Xgt::Ruby::Auth.wif_to_public_key(money_private, address_prefix)
|
|
29
|
+
social_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'social')
|
|
30
|
+
social_public = Xgt::Ruby::Auth.wif_to_public_key(social_private, address_prefix)
|
|
31
|
+
memo_private = Xgt::Ruby::Auth.generate_wif(current_name, master, 'memo')
|
|
32
|
+
memo_public = Xgt::Ruby::Auth.wif_to_public_key(memo_private, address_prefix)
|
|
33
|
+
|
|
34
|
+
txn = {
|
|
35
|
+
'extensions': [],
|
|
36
|
+
'operations': [
|
|
37
|
+
[
|
|
38
|
+
'account_create',
|
|
39
|
+
{
|
|
40
|
+
'fee': creation_fee,
|
|
41
|
+
'creator': current_name,
|
|
42
|
+
'recovery': {
|
|
43
|
+
'weight_threshold': 1,
|
|
44
|
+
'account_auths': [],
|
|
45
|
+
'key_auths': [[recovery_public, 1]]
|
|
46
|
+
},
|
|
47
|
+
'money': {
|
|
48
|
+
'weight_threshold': 1,
|
|
49
|
+
'account_auths': [],
|
|
50
|
+
'key_auths': [[money_public, 1]]
|
|
51
|
+
},
|
|
52
|
+
'social': {
|
|
53
|
+
'weight_threshold': 1,
|
|
54
|
+
'account_auths': [],
|
|
55
|
+
'key_auths': [[social_public, 1]]
|
|
56
|
+
},
|
|
57
|
+
'memo_key': memo_public,
|
|
58
|
+
'json_metadata': "",
|
|
59
|
+
'extensions': []
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
signed = Xgt::Ruby::Auth.sign_transaction(rpc, txn, [wif], chain_id)
|
|
66
|
+
signed
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
load 'dummy_code.rb'
|
|
3
|
+
|
|
4
|
+
def get_transaction_hex(transaction)
|
|
5
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
6
|
+
wif = '5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n'
|
|
7
|
+
config = rpc.call('database_api.get_config', {})
|
|
8
|
+
chain_id = config["XGT_CHAIN_ID"]
|
|
9
|
+
|
|
10
|
+
signed = Xgt::Ruby::Auth.sign_transaction(rpc, transaction, [wif], chain_id)
|
|
11
|
+
response = rpc.call('network_broadcast_api.get_transaction_hex', [transaction])
|
|
12
|
+
|
|
13
|
+
puts JSON.pretty_generate(response)
|
|
14
|
+
response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
get_transaction_hex(Dummy_code.account_create())
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
load 'dummy_code.rb'
|
|
3
|
+
|
|
4
|
+
def broadcast_block(signed_block)
|
|
5
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
6
|
+
payload = {
|
|
7
|
+
signed_block: signed_block
|
|
8
|
+
}
|
|
9
|
+
response = rpc.call('network_broadcast_api.broadcast_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
|
+
broadcast_block('0')
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'xgt/ruby'
|
|
2
|
+
|
|
3
|
+
def transfer
|
|
4
|
+
# Connect to chain
|
|
5
|
+
wif = '5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n'
|
|
6
|
+
rpc = Xgt::Ruby::Rpc.new('http://localhost:8751')
|
|
7
|
+
config = rpc.call('database_api.get_config', {})
|
|
8
|
+
chain_id = config['XGT_CHAIN_ID']
|
|
9
|
+
witness_schedule = rpc.call('database_api.get_witness_schedule', {}) || {}
|
|
10
|
+
chain_properties = witness_schedule['median_props']
|
|
11
|
+
fee = chain_properties['account_creation_fee'] || {}
|
|
12
|
+
amount = fee['amount'].to_f * 0.001
|
|
13
|
+
creation_fee = "#{'%0.3f' % amount} XGT"
|
|
14
|
+
currency_symbol = creation_fee.split(/\s+/).last
|
|
15
|
+
string_amount = '%.3f' % (1000 * 0.001)
|
|
16
|
+
|
|
17
|
+
txn = {
|
|
18
|
+
'extensions': [],
|
|
19
|
+
'operations': [
|
|
20
|
+
[
|
|
21
|
+
'transfer',
|
|
22
|
+
{
|
|
23
|
+
'from': 'XGT0000000000000',
|
|
24
|
+
'to': 'XGT272up7iTGKArE',
|
|
25
|
+
'amount': %(#{string_amount} #{currency_symbol}),
|
|
26
|
+
'memo': 'thanks hoss',
|
|
27
|
+
'json_metadata': '',
|
|
28
|
+
'extensions': []
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
puts "\e[36mSent:\n\e[0m"
|
|
35
|
+
puts JSON.pretty_generate(txn)
|
|
36
|
+
signed = Xgt::Ruby::Auth.sign_transaction(rpc, txn, [wif], chain_id)
|
|
37
|
+
puts "\e[36m\nSigned:\n\e[0m"
|
|
38
|
+
puts JSON.pretty_generate(signed)
|
|
39
|
+
response = rpc.call('call', ['network_broadcast_api', 'broadcast_transaction_synchronous', [signed]])
|
|
40
|
+
puts "\e[36m\nResponse:\n\e[0m"
|
|
41
|
+
puts JSON.pretty_generate(response)
|
|
42
|
+
response
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
transfer
|