crea-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +55 -0
  3. data/CONTRIBUTING.md +79 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +22 -0
  6. data/README.md +234 -0
  7. data/Rakefile +332 -0
  8. data/crea-ruby.gemspec +39 -0
  9. data/gource.sh +6 -0
  10. data/lib/crea.rb +85 -0
  11. data/lib/crea/api.rb +208 -0
  12. data/lib/crea/base_error.rb +218 -0
  13. data/lib/crea/block_api.rb +78 -0
  14. data/lib/crea/broadcast.rb +1334 -0
  15. data/lib/crea/chain_config.rb +36 -0
  16. data/lib/crea/formatter.rb +14 -0
  17. data/lib/crea/jsonrpc.rb +108 -0
  18. data/lib/crea/marshal.rb +231 -0
  19. data/lib/crea/mixins/jsonable.rb +37 -0
  20. data/lib/crea/mixins/retriable.rb +58 -0
  21. data/lib/crea/mixins/serializable.rb +45 -0
  22. data/lib/crea/operation.rb +141 -0
  23. data/lib/crea/operation/account_create.rb +10 -0
  24. data/lib/crea/operation/account_create_with_delegation.rb +12 -0
  25. data/lib/crea/operation/account_update.rb +8 -0
  26. data/lib/crea/operation/account_witness_proxy.rb +4 -0
  27. data/lib/crea/operation/account_witness_vote.rb +5 -0
  28. data/lib/crea/operation/cancel_transfer_from_savings.rb +4 -0
  29. data/lib/crea/operation/challenge_authority.rb +5 -0
  30. data/lib/crea/operation/change_recovery_account.rb +5 -0
  31. data/lib/crea/operation/claim_account.rb +5 -0
  32. data/lib/crea/operation/claim_reward_balance.rb +6 -0
  33. data/lib/crea/operation/comment.rb +9 -0
  34. data/lib/crea/operation/comment_options.rb +10 -0
  35. data/lib/crea/operation/convert.rb +5 -0
  36. data/lib/crea/operation/create_claimed_account.rb +10 -0
  37. data/lib/crea/operation/custom.rb +5 -0
  38. data/lib/crea/operation/custom_binary.rb +8 -0
  39. data/lib/crea/operation/custom_json.rb +6 -0
  40. data/lib/crea/operation/decline_voting_rights.rb +4 -0
  41. data/lib/crea/operation/delegate_vesting_shares.rb +5 -0
  42. data/lib/crea/operation/delete_comment.rb +4 -0
  43. data/lib/crea/operation/escrow_approve.rb +8 -0
  44. data/lib/crea/operation/escrow_dispute.rb +7 -0
  45. data/lib/crea/operation/escrow_release.rb +10 -0
  46. data/lib/crea/operation/escrow_transfer.rb +12 -0
  47. data/lib/crea/operation/feed_publish.rb +4 -0
  48. data/lib/crea/operation/limit_order_cancel.rb +4 -0
  49. data/lib/crea/operation/limit_order_create.rb +8 -0
  50. data/lib/crea/operation/limit_order_create2.rb +8 -0
  51. data/lib/crea/operation/prove_authority.rb +4 -0
  52. data/lib/crea/operation/recover_account.rb +6 -0
  53. data/lib/crea/operation/report_over_production.rb +5 -0
  54. data/lib/crea/operation/request_account_recovery.rb +6 -0
  55. data/lib/crea/operation/reset_account.rb +5 -0
  56. data/lib/crea/operation/set_reset_account.rb +5 -0
  57. data/lib/crea/operation/set_withdraw_vesting_route.rb +6 -0
  58. data/lib/crea/operation/transfer.rb +6 -0
  59. data/lib/crea/operation/transfer_from_savings.rb +7 -0
  60. data/lib/crea/operation/transfer_to_savings.rb +6 -0
  61. data/lib/crea/operation/transfer_to_vesting.rb +5 -0
  62. data/lib/crea/operation/vote.rb +6 -0
  63. data/lib/crea/operation/withdraw_vesting.rb +4 -0
  64. data/lib/crea/operation/witness_set_properties.rb +5 -0
  65. data/lib/crea/operation/witness_update.rb +7 -0
  66. data/lib/crea/rpc/base_client.rb +179 -0
  67. data/lib/crea/rpc/http_client.rb +143 -0
  68. data/lib/crea/rpc/thread_safe_http_client.rb +35 -0
  69. data/lib/crea/stream.rb +385 -0
  70. data/lib/crea/transaction.rb +96 -0
  71. data/lib/crea/transaction_builder.rb +393 -0
  72. data/lib/crea/type/amount.rb +107 -0
  73. data/lib/crea/type/base_type.rb +10 -0
  74. data/lib/crea/utils.rb +17 -0
  75. data/lib/crea/version.rb +4 -0
  76. metadata +478 -0
@@ -0,0 +1,45 @@
1
+ module Crea
2
+ module Serializable
3
+ NUMERIC_TYPES = %i(unsigned_char uint16 uint32 uint64 signed_char int16 int32
4
+ int64 varint)
5
+
6
+ KNOWN_TYPES = NUMERIC_TYPES + %i(boolean string raw_bytes point_in_time
7
+ public_key amount price authority optional_authority
8
+ comment_options_extensions beneficiaries chain_properties required_auths
9
+ witness_properties empty_array lambda)
10
+
11
+ module ClassMethods
12
+ def def_attr key_pair
13
+ name = key_pair.keys.first.to_sym
14
+ type = key_pair.values.first.to_sym
15
+
16
+ self.attributes ||= []
17
+ self.attributes << name
18
+
19
+ attr_accessor *attributes
20
+ add_type name, type
21
+ end
22
+
23
+ def add_type name, type
24
+ name = name.to_sym
25
+ type = type.to_sym
26
+ raise "Unknown type: #{type}" unless KNOWN_TYPES.include? type
27
+
28
+ @serializable_types ||= {}
29
+ @serializable_types[name] = type
30
+ end
31
+
32
+ def numeric?(name)
33
+ NUMERIC_TYPES.include? @serializable_types[name.to_sym]
34
+ end
35
+
36
+ def serializable_types
37
+ @serializable_types
38
+ end
39
+ end
40
+
41
+ def self.included(base)
42
+ base.extend(ClassMethods)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,141 @@
1
+ module Crea
2
+ class Operation
3
+ include JSONable
4
+ include Serializable
5
+ include Utils
6
+
7
+ # IDs derrived from:
8
+ # https://github.com/creary/crea/blob/127a441fbac2f06804359968bda83b66e602c891/libraries/protocol/include/crea/protocol/operations.hpp
9
+
10
+ IDS = [
11
+ :vote_operation,
12
+ :comment_operation,
13
+
14
+ :transfer_operation,
15
+ :transfer_to_vesting_operation,
16
+ :withdraw_vesting_operation,
17
+
18
+ :limit_order_create_operation,
19
+ :limit_order_cancel_operation,
20
+
21
+ :feed_publish_operation,
22
+ :convert_operation,
23
+
24
+ :account_create_operation,
25
+ :account_update_operation,
26
+
27
+ :witness_update_operation,
28
+ :account_witness_vote_operation,
29
+ :account_witness_proxy_operation,
30
+
31
+ :pow_operation,
32
+
33
+ :custom_operation,
34
+
35
+ :report_over_production_operation,
36
+
37
+ :delete_comment_operation,
38
+ :custom_json_operation,
39
+ :comment_options_operation,
40
+ :set_withdraw_vesting_route_operation,
41
+ :limit_order_create2_operation,
42
+ :claim_account_operation,
43
+ :create_claimed_account_operation,
44
+ :request_account_recovery_operation,
45
+ :recover_account_operation,
46
+ :change_recovery_account_operation,
47
+ :escrow_transfer_operation,
48
+ :escrow_dispute_operation,
49
+ :escrow_release_operation,
50
+ :pow2_operation,
51
+ :escrow_approve_operation,
52
+ :transfer_to_savings_operation,
53
+ :transfer_from_savings_operation,
54
+ :cancel_transfer_from_savings_operation,
55
+ :custom_binary_operation,
56
+ :decline_voting_rights_operation,
57
+ :reset_account_operation,
58
+ :set_reset_account_operation,
59
+ :claim_reward_balance_operation,
60
+ :delegate_vesting_shares_operation,
61
+ :account_create_with_delegation_operation,
62
+ :witness_set_properties_operation,
63
+
64
+ # SMT operations
65
+ :claim_reward_balance2_operation,
66
+
67
+ :smt_setup_operation,
68
+ :smt_cap_reveal_operation,
69
+ :smt_refund_operation,
70
+ :smt_setup_emissions_operation,
71
+ :smt_set_setup_parameters_operation,
72
+ :smt_set_runtime_parameters_operation,
73
+ :smt_create_operation,
74
+
75
+ # virtual operations below this point
76
+ :fill_convert_request_operation,
77
+ :author_reward_operation,
78
+ :curation_reward_operation,
79
+ :comment_reward_operation,
80
+ :liquidity_reward_operation,
81
+ :interest_operation,
82
+ :fill_vesting_withdraw_operation,
83
+ :fill_order_operation,
84
+ :shutdown_witness_operation,
85
+ :fill_transfer_from_savings_operation,
86
+ :hardfork_operation,
87
+ :comment_payout_update_operation,
88
+ :return_vesting_delegation_operation,
89
+ :comment_benefactor_reward_operation,
90
+ :producer_reward_operation,
91
+ :clear_null_account_balance_operation
92
+ ]
93
+
94
+ def self.op_id(op)
95
+ IDS.find_index op
96
+ end
97
+
98
+ def inspect
99
+ properties = self.class.attributes.map do |prop|
100
+ unless (v = instance_variable_get("@#{prop}")).nil?
101
+ v = if v.respond_to? :strftime
102
+ v.strftime('%Y-%m-%dT%H:%M:%S')
103
+ else
104
+ v
105
+ end
106
+
107
+ "@#{prop}=#{v}"
108
+ end
109
+ end.compact.join(', ')
110
+
111
+ "#<#{self.class.name} [#{properties}]>"
112
+ end
113
+
114
+ def [](key)
115
+ key = key.to_sym
116
+ send(key) if self.class.attributes.include?(key)
117
+ end
118
+
119
+ def []=(key, value)
120
+ key = key.to_sym
121
+
122
+ if self.class.attributes.include?(key)
123
+ if self.class.numeric? key
124
+ send("#{key}=", value.to_i)
125
+ else
126
+ send("#{key}=", value)
127
+ end
128
+ end
129
+ end
130
+
131
+ def ==(other_op)
132
+ return false if self.class != other_op.class
133
+
134
+ self.class.attributes.each do |prop|
135
+ return false if self[prop] != other_op[prop]
136
+ end
137
+
138
+ true
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,10 @@
1
+ class Crea::Operation::AccountCreate < Crea::Operation
2
+ def_attr fee: :amount
3
+ def_attr creator: :string
4
+ def_attr new_account_name: :string
5
+ def_attr owner: :authority
6
+ def_attr active: :authority
7
+ def_attr posting: :authority
8
+ def_attr memo_key: :public_key
9
+ def_attr json_metadata: :string
10
+ end
@@ -0,0 +1,12 @@
1
+ class Crea::Operation::AccountCreateWithDelegation < Crea::Operation
2
+ def_attr fee: :amount
3
+ def_attr delegation: :amount
4
+ def_attr creator: :string
5
+ def_attr new_account_name: :string
6
+ def_attr owner: :authority
7
+ def_attr active: :authority
8
+ def_attr posting: :authority
9
+ def_attr memo_key: :public_key
10
+ def_attr json_metadata: :string
11
+ def_attr extensions: :empty_array
12
+ end
@@ -0,0 +1,8 @@
1
+ class Crea::Operation::AccountUpdate < Crea::Operation
2
+ def_attr account: :string
3
+ def_attr owner: :optional_authority
4
+ def_attr active: :optional_authority
5
+ def_attr posting: :optional_authority
6
+ def_attr memo_key: :public_key
7
+ def_attr json_metadata: :string
8
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::AccountWitnessProxy < Crea::Operation
2
+ def_attr account: :string
3
+ def_attr proxy: :string
4
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::AccountWitnessVote < Crea::Operation
2
+ def_attr account: :string
3
+ def_attr witness: :string
4
+ def_attr approve: :boolean
5
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::CancelTransferFromSavings < Crea::Operation
2
+ def_attr from: :string
3
+ def_attr request_id: :uint32
4
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::ChallengeAuthority < Crea::Operation
2
+ def_attr challenger: :string
3
+ def_attr challenged: :string
4
+ def_attr require_owner: :boolean
5
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::ChangeRecoveryAccount < Crea::Operation
2
+ def_attr account_to_recover: :string
3
+ def_attr new_recovery_account: :string
4
+ def_attr extensions: :empty_array
5
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::ClaimAccount < Crea::Operation
2
+ def_attr creator: :string
3
+ def_attr fee: :amount
4
+ def_attr extensions: :empty_array
5
+ end
@@ -0,0 +1,6 @@
1
+ class Crea::Operation::ClaimRewardBalance < Crea::Operation
2
+ def_attr account: :string
3
+ def_attr reward_crea: :amount
4
+ def_attr reward_cbd: :amount
5
+ def_attr reward_vests: :amount
6
+ end
@@ -0,0 +1,9 @@
1
+ class Crea::Operation::Comment < Crea::Operation
2
+ def_attr parent_author: :string
3
+ def_attr parent_permlink: :string
4
+ def_attr author: :string
5
+ def_attr permlink: :string
6
+ def_attr title: :string
7
+ def_attr body: :string
8
+ def_attr json_metadata: :string
9
+ end
@@ -0,0 +1,10 @@
1
+ class Crea::Operation::CommentOptions < Crea::Operation
2
+ def_attr author: :string
3
+ def_attr permlink: :string
4
+ def_attr max_accepted_payout: :amount
5
+ def_attr percent_crea_dollars: :uint32
6
+ # def_attr allow_replies: :boolean
7
+ def_attr allow_votes: :boolean
8
+ def_attr allow_curation_rewards: :boolean
9
+ def_attr extensions: :comment_options_extensions
10
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::Convert < Crea::Operation
2
+ def_attr owner: :string
3
+ def_attr requestid: :uint32
4
+ def_attr amount: :amount
5
+ end
@@ -0,0 +1,10 @@
1
+ class Crea::Operation::CreateClaimedAccount < Crea::Operation
2
+ def_attr creator: :string
3
+ def_attr new_account_name: :string
4
+ def_attr owner: :authority
5
+ def_attr active: :authority
6
+ def_attr posting: :authority
7
+ def_attr memo_key: :public_key
8
+ def_attr json_metadata: :string
9
+ def_attr extensions: :empty_array
10
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::Custom < Crea::Operation
2
+ def_attr required_auths: :required_auths
3
+ def_attr id: :uint32
4
+ def_attr data: :raw_bytes
5
+ end
@@ -0,0 +1,8 @@
1
+ class Crea::Operation::CustomBinary < Crea::Operation
2
+ def_attr required_owner_auths: :required_auths
3
+ def_attr required_active_auths: :required_auths
4
+ def_attr required_posting_auths: :required_auths
5
+ def_attr required_auths: :required_auths
6
+ def_attr id: :string
7
+ def_attr data: :raw_bytes
8
+ end
@@ -0,0 +1,6 @@
1
+ class Crea::Operation::CustomJson < Crea::Operation
2
+ def_attr required_auths: :required_auths
3
+ def_attr required_posting_auths: :required_auths
4
+ def_attr id: :string
5
+ def_attr json: :string
6
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::DeclineVotingRights < Crea::Operation
2
+ def_attr account: :string
3
+ def_attr decline: :boolean
4
+ end
@@ -0,0 +1,5 @@
1
+ class Crea::Operation::DelegateVestingShares < Crea::Operation
2
+ def_attr delegator: :string
3
+ def_attr delegatee: :string
4
+ def_attr vesting_shares: :amount
5
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::DeleteComment < Crea::Operation
2
+ def_attr author: :string
3
+ def_attr permlink: :string
4
+ end
@@ -0,0 +1,8 @@
1
+ class Crea::Operation::EscrowApprove < Crea::Operation
2
+ def_attr from: :string
3
+ def_attr to: :string
4
+ def_attr agent: :string
5
+ def_attr who: :string
6
+ def_attr escrow_id: :uint32
7
+ def_attr approve: :boolean
8
+ end
@@ -0,0 +1,7 @@
1
+ class Crea::Operation::EscrowDispute < Crea::Operation
2
+ def_attr from: :string
3
+ def_attr to: :string
4
+ def_attr agent: :string
5
+ def_attr who: :string
6
+ def_attr escrow_id: :uint32
7
+ end
@@ -0,0 +1,10 @@
1
+ class Crea::Operation::EscrowRelease < Crea::Operation
2
+ def_attr from: :string
3
+ def_attr to: :string
4
+ def_attr agent: :string
5
+ def_attr who: :string
6
+ def_attr receiver: :string
7
+ def_attr escrow_id: :uint32
8
+ def_attr cbd_amount: :amount
9
+ def_attr crea_amount: :amount
10
+ end
@@ -0,0 +1,12 @@
1
+ class Crea::Operation::EscrowTransfer < Crea::Operation
2
+ def_attr from: :string
3
+ def_attr to: :string
4
+ def_attr cbd_amount: :amount
5
+ def_attr crea_amount: :amount
6
+ def_attr escrow_id: :uint32
7
+ def_attr agent: :string
8
+ def_attr fee: :amount
9
+ def_attr json_metadata: :string
10
+ def_attr ratification_deadline: :point_in_time
11
+ def_attr escrow_expiration: :point_in_time
12
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::FeedPublish < Crea::Operation
2
+ def_attr publisher: :string
3
+ def_attr exchange_rate: :price
4
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::LimitOrderCancel < Crea::Operation
2
+ def_attr owner: :string
3
+ def_attr orderid: :uint32
4
+ end
@@ -0,0 +1,8 @@
1
+ class Crea::Operation::LimitOrderCreate < Crea::Operation
2
+ def_attr owner: :string
3
+ def_attr orderid: :uint32
4
+ def_attr amount_to_sell: :amount
5
+ def_attr min_to_receive: :amount
6
+ def_attr fill_or_kill: :boolean
7
+ def_attr expiration: :point_in_time
8
+ end
@@ -0,0 +1,8 @@
1
+ class Crea::Operation::LimitOrderCreate2 < Crea::Operation
2
+ def_attr owner: :string
3
+ def_attr orderid: :uint32
4
+ def_attr amount_to_sell: :amount
5
+ def_attr fill_or_kill: :boolean
6
+ def_attr exchange_rate: :price
7
+ def_attr expiration: :point_in_time
8
+ end
@@ -0,0 +1,4 @@
1
+ class Crea::Operation::ProveAuthority < Crea::Operation
2
+ def_attr challenged: :string
3
+ def_attr require_owner: :boolean
4
+ end