Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14 deserialization #15

Merged
merged 2 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PATH
remote: .
specs:
steem-ruby (0.9.3)
steem-ruby (0.9.4)
base58 (~> 0.2, >= 0.2.3)
bindata (~> 2.4, >= 2.4.4)
bitcoin-ruby (~> 0.0, >= 0.0.18)
ffi (~> 1.9, >= 1.9.23)
hashie (~> 3.5, >= 3.5.7)
Expand All @@ -14,6 +16,8 @@ GEM
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
awesome_print (1.8.0)
base58 (0.2.3)
bindata (2.4.4)
bitcoin-ruby (0.0.18)
coderay (1.1.2)
crack (0.4.3)
Expand All @@ -27,17 +31,17 @@ GEM
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
method_source (0.9.0)
method_source (0.9.1)
minitest (5.11.3)
minitest-line (0.6.5)
minitest (~> 5.0)
minitest-proveit (1.0.0)
minitest (> 5, < 7)
multi_json (1.13.1)
pry (0.11.3)
pry (0.12.0)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.2)
public_suffix (3.0.3)
rake (12.3.1)
safe_yaml (1.0.4)
simplecov (0.16.1)
Expand All @@ -50,7 +54,7 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
yard (0.9.15)
yard (0.9.16)

PLATFORMS
ruby
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ The `steem-ruby` gem was written from the ground up by `@inertia`, who is also t

> "I intend to continue work on `radiator` indefinitely. But in `radiator-0.5`, I intend to refactor `radiator` so that is uses `steem-ruby` as its core. This means that some features of `radiator` like Serialization will become redundant. I think it's still useful for radiator to do its own serialization because it reduces the number of API requests." - @inertia

| `radiator` | `steem-ruby` |
|-|-|
| Has internal failover logic | Can have failover delegated externally |
| Passes `error` responses to the caller | Handles `error` responses and raises exceptions |
| Supports tx signing, does its own serialization | Also supports tx signing, but delegates serialization to `database_api.get_transaction_hex` |
| All apis and methods are hardcoded | Asks `jsonrpc` what apis and methods are available from the node |
| (`radiator-0.4.x`) Only supports AppBase but relies on `condenser_api` | Only supports AppBase but does not rely on `condenser_api` **(WIP)**
| Small list of helper methods for select ops (in addition to build your own transaction) | Complete implementation of helper methods for every op (in addition to build your own transaction) |
| Does not (yet) support `json-rpc-batch` requests | Supports `json-rpc-batch` requests |
`radiator` | `steem-ruby`
---------- | ------------
Has internal failover logic | Can have failover delegated externally
Passes `error` responses to the caller | Handles `error` responses and raises exceptions
Supports tx signing, does its own serialization | Also supports tx signing, but delegates serialization to `database_api.get_transaction_hex`, then deserializes to verify
All apis and methods are hardcoded | Asks `jsonrpc` what apis and methods are available from the node
(`radiator-0.4.x`) Only supports AppBase but relies on `condenser_api` | Only supports AppBase but does not rely on `condenser_api` **(WIP)**
Small list of helper methods for select ops (in addition to build your own transaction) | Complete implementation of helper methods for every op (in addition to build your own transaction)
Does not (yet) support `json-rpc-batch` requests | Supports `json-rpc-batch` requests

## Getting Started

Expand Down Expand Up @@ -186,7 +186,7 @@ trx = open('trx.json').read
builder = Steem::TransactionBuilder.new(wif: wif2, trx: trx)
api = Steem::CondenserApi.new
trx = builder.transaction
api.broadcast_transaction_synchronous(trx: trx)
api.broadcast_transaction_synchronous(trx)
```

### Get Accounts
Expand Down
48 changes: 48 additions & 0 deletions lib/steem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,58 @@
require 'steem/version'
require 'steem/utils'
require 'steem/base_error'
require 'steem/mixins/serializable'
require 'steem/mixins/jsonable'
require 'steem/mixins/retriable'
require 'steem/chain_config'
require 'steem/type/base_type'
require 'steem/type/amount'
require 'steem/operation'
require 'steem/operation/account_create.rb'
require 'steem/operation/account_create_with_delegation.rb'
require 'steem/operation/account_update.rb'
require 'steem/operation/account_witness_proxy.rb'
require 'steem/operation/account_witness_vote.rb'
require 'steem/operation/cancel_transfer_from_savings.rb'
require 'steem/operation/challenge_authority.rb'
require 'steem/operation/change_recovery_account.rb'
require 'steem/operation/claim_account.rb'
require 'steem/operation/claim_reward_balance.rb'
require 'steem/operation/comment.rb'
require 'steem/operation/comment_options.rb'
require 'steem/operation/convert.rb'
require 'steem/operation/create_claimed_account.rb'
require 'steem/operation/custom.rb'
require 'steem/operation/custom_binary.rb'
require 'steem/operation/custom_json.rb'
require 'steem/operation/decline_voting_rights.rb'
require 'steem/operation/delegate_vesting_shares.rb'
require 'steem/operation/delete_comment.rb'
require 'steem/operation/escrow_approve.rb'
require 'steem/operation/escrow_dispute.rb'
require 'steem/operation/escrow_release.rb'
require 'steem/operation/escrow_transfer.rb'
require 'steem/operation/feed_publish.rb'
require 'steem/operation/limit_order_cancel.rb'
require 'steem/operation/limit_order_create.rb'
require 'steem/operation/limit_order_create2.rb'
require 'steem/operation/prove_authority.rb'
require 'steem/operation/recover_account.rb'
require 'steem/operation/report_over_production.rb'
require 'steem/operation/request_account_recovery.rb'
require 'steem/operation/reset_account.rb'
require 'steem/operation/set_reset_account.rb'
require 'steem/operation/set_withdraw_vesting_route.rb'
require 'steem/operation/transfer.rb'
require 'steem/operation/transfer_from_savings.rb'
require 'steem/operation/transfer_to_savings.rb'
require 'steem/operation/transfer_to_vesting.rb'
require 'steem/operation/vote.rb'
require 'steem/operation/withdraw_vesting.rb'
require 'steem/operation/witness_update.rb'
require 'steem/operation/witness_set_properties.rb'
require 'steem/marshal'
require 'steem/transaction'
require 'steem/transaction_builder'
require 'steem/rpc/base_client'
require 'steem/rpc/http_client'
Expand Down
8 changes: 5 additions & 3 deletions lib/steem/base_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def to_s
detail[:error] = @error if !!@error
detail[:cause] = @cause if !!@cause

JSON[detail] rescue detai.to_s
JSON[detail] rescue detail.to_s
end

def self.build_error(error, context)
Expand All @@ -19,11 +19,11 @@ def self.build_error(error, context)
end

if error.message.include? 'Internal Error'
raise Steem::RemoteNodeError.new, error.message, build_backtrace(error)
raise Steem::RemoteNodeError, error.message, build_backtrace(error)
end

if error.message.include? 'Server error'
raise Steem::RemoteNodeError.new, error.message, build_backtrace(error)
raise Steem::RemoteNodeError, error.message, build_backtrace(error)
end

if error.message.include? 'plugin not enabled'
Expand Down Expand Up @@ -176,6 +176,8 @@ def self.build_backtrace(error)
end
end

class DeserializationError < BaseError; end
class SerializationMismatchError < BaseError; end
class UnsupportedChainError < BaseError; end
class ArgumentError < BaseError; end
class TypeError < BaseError; end
Expand Down
23 changes: 20 additions & 3 deletions lib/steem/broadcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,17 @@ def self.comment(options, &block)
permlink: params[:permlink],
max_accepted_payout: max_accepted_payout,
percent_steem_dollars: params[:percent_steem_dollars] || 10000,
# allow_replies: allow_replies,
allow_votes: allow_votes,
allow_curation_rewards: allow_curation_rewards,
extensions: []
}

if !!params[:beneficiaries]
comment_options[:extensions] << [0, {beneficiaries: params[:beneficiaries]}]
comment_options[:extensions] << [
comment_options[:extensions].size,
normalize_beneficiaries(options.merge(beneficiaries: params[:beneficiaries]))
]
end

ops << [:comment_options, comment_options]
Expand Down Expand Up @@ -714,13 +718,21 @@ def self.witness_set_properties(options, &block)
end

if !!(sbd_exchange_rate = params[:props][:sbd_exchange_rate] rescue nil)
params[:props][:sbd_exchange_rate] = normalize_amount(options.merge amount: sbd_exchange_rate, serialize: true)
params[:props][:sbd_exchange_rate][:base] = normalize_amount(options.merge amount: sbd_exchange_rate[:base], serialize: true)
params[:props][:sbd_exchange_rate][:quote] = normalize_amount(options.merge amount: sbd_exchange_rate[:quote], serialize: true)
params[:props][:sbd_exchange_rate] = params[:props][:sbd_exchange_rate].to_json
end

%i(key new_signing_key).each do |key|
if !!params[key] && params[key].size == 53
params[key] = params[key][3..-1]
end
end

%i(account_creation_fee sbd_exchange_rate url new_signing_key).each do |key|
next unless !!params[:props][key]

val = params[:props][key]
val = params[:props][key].to_s

params[:props][key] = hexlify val unless val =~ /^[0-9A-F]+$/i
end
Expand Down Expand Up @@ -1282,6 +1294,11 @@ def self.normalize_amount(options)
end
end

def self.normalize_beneficiaries(options)
# Type::Beneficiaries.new(options[:beneficiaries])
{beneficiaries: options[:beneficiaries]}
end

# @private
def self.database_api(options)
options[:database_api] ||= if !!options[:app_base]
Expand Down
Loading