Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Add onetime signer support, and ruby sdk client helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nullstyle committed Jul 10, 2018
1 parent 38940ae commit b365dab
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
gemspec

# gem 'stellar-base', path: "~/src/stellar/ruby-stellar-base"
# gem 'stellar-base', path: "~/prj/stellar/ruby-stellar-base"
# gem 'xdr', path: "~/src/stellar/ruby-xdr"#
12 changes: 12 additions & 0 deletions examples/onetime_signer.rb
@@ -0,0 +1,12 @@
account :scott
puts "scott: #{get_account(:scott).address}"
create_via_friendbot :scott
wait

pp get_account_info(:scott).signers

add_onetime_signer :scott, "hello world", 1

wait

pp get_account_info(:scott).signers
1 change: 1 addition & 0 deletions lib/stellar_core_commander.rb
@@ -1,6 +1,7 @@
require "stellar_core_commander/version"
require "active_support/all"
require "stellar-base"
require "stellar-sdk"
require "contracts"
require "faraday"
require "faraday_middleware"
Expand Down
1 change: 1 addition & 0 deletions lib/stellar_core_commander/concerns/named_objects.rb
Expand Up @@ -12,6 +12,7 @@ def add_named(name, object)
raise ArgumentError, "#{name} is already registered"
end
@named[name] = object
object
end

Contract Symbol => Any
Expand Down
1 change: 0 additions & 1 deletion lib/stellar_core_commander/concerns/tracks_accounts.rb
Expand Up @@ -25,7 +25,6 @@ def get_account(name)
end
end


end
end
end
27 changes: 19 additions & 8 deletions lib/stellar_core_commander/horizon_commander.rb
Expand Up @@ -14,9 +14,9 @@ def initialize(endpoint)
@open = []
@sequences = SequenceTracker.new(self)
@conn = Faraday.new(:url => @endpoint) do |faraday|
faraday.request :retry, max: 2
faraday.use FaradayMiddleware::FollowRedirects
faraday.adapter :typhoeus
faraday.request :retry, max: 2
end

@transaction_builder = TransactionBuilder.new(self)
Expand Down Expand Up @@ -97,8 +97,9 @@ def self.recipe_steps(names)
:clear_flags,
:require_trust_auth,
:add_signer,
:set_master_signer_weight,
:remove_signer,
:add_onetime_signer,
:set_master_signer_weight,
:set_thresholds,
:set_inflation_dest,
:set_home_domain,
Expand All @@ -119,6 +120,22 @@ def sequence_for(account)
body["sequence"].to_i
end

Contract Symbol => Any
def create_via_friendbot(account)
account = get_account account
@open << @conn.get("friendbot", addr: account.address)
end

Contract None => Stellar::Client
def sdk_client
@client ||= Stellar::Client.new(horizon: @endpoint)
end

Contract Symbol => Hyperclient::Resource
def get_account_info(name)
sdk_account = Stellar::Account.new(get_account(name))
sdk_client.account_info(sdk_account)
end

private

Expand All @@ -129,12 +146,6 @@ def submit_transaction(envelope, &after_confirmation)
@open << @conn.post("transactions", tx: b64)
end

Contract Symbol => Any
def create_via_friendbot(account)
account = get_account account
@open << @conn.get("friendbot", addr: account.address)
end

Contract Exception => Any
def crash_recipe(e)
puts
Expand Down
8 changes: 8 additions & 0 deletions lib/stellar_core_commander/transaction_builder.rb
Expand Up @@ -245,6 +245,14 @@ def remove_signer(account, key)
add_signer account, key, 0
end

Contract Symbol, String, Num => Any
def add_onetime_signer(account, preimage, weight)
set_options account, signer: Stellar::Signer.new({
key: Stellar::SignerKey.onetime_signer(preimage),
weight: weight
})
end

Contract(Symbol, MasterWeightByte => Any)
def set_master_signer_weight(account, weight)
set_options account, master_weight: weight
Expand Down
8 changes: 6 additions & 2 deletions lib/stellar_core_commander/transactor.rb
Expand Up @@ -139,11 +139,15 @@ def payment(*args, &block)
# @see StellarCoreCommander::TransactionBuilder#add_signer
recipe_step :add_signer

# @see StellarCoreCommander::TransactionBuilder#remove_signer
recipe_step :remove_signer

# @see StellarCoreCommander::TransactionBuilder#add_onetime_signer
recipe_step :add_onetime_signer

# @see StellarCoreCommander::TransactionBuilder#set_master_signer_weight
recipe_step :set_master_signer_weight

# @see StellarCoreCommander::TransactionBuilder#remove_signer
recipe_step :remove_signer

# @see StellarCoreCommander::TransactionBuilder#set_thresholds
recipe_step :set_thresholds
Expand Down
7 changes: 4 additions & 3 deletions stellar_core_commander.gemspec
Expand Up @@ -17,14 +17,15 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "stellar-base", ">= 0.12.0"
spec.add_dependency "stellar-base", ">= 0.16.0"
spec.add_dependency "stellar-sdk", ">= 0.5.0"
spec.add_dependency "slop", "~> 3.6.0"
spec.add_dependency "faraday", "~> 0.9.1"
spec.add_dependency "faraday_middleware", "~> 0.9.1"
spec.add_dependency "pg", "~> 0.18.1"
spec.add_dependency "sequel", "~> 5.5.0"
spec.add_dependency "activesupport", ">= 4.0.0"
spec.add_dependency "contracts", "~> 0.9"
spec.add_dependency "activesupport", ">= 5.2.0"
spec.add_dependency "contracts", "~> 0.16"
spec.add_dependency "typhoeus", "~> 0.8.0"
spec.add_dependency "pry", "~> 0.11.3"

Expand Down

0 comments on commit b365dab

Please sign in to comment.