class Mobius::Client::Blockchain::AddCosigner

Adds account as cosigner to other account.

Public Instance Methods

call() click to toggle source

Executes an operation

# File lib/mobius/client/blockchain/add_cosigner.rb, line 26
def call
  client.horizon.transactions._post(
    tx: tx.to_envelope(keypair).to_xdr(:base64)
  )
rescue Faraday::ResourceNotFound
  raise Mobius::Client::Error::AccountMissing
end

Private Instance Methods

account() click to toggle source
# File lib/mobius/client/blockchain/add_cosigner.rb, line 69
def account
  @account ||= Mobius::Client::Blockchain::Account.new(keypair)
end
add_cosigner_op() click to toggle source
# File lib/mobius/client/blockchain/add_cosigner.rb, line 47
def add_cosigner_op
  Stellar::Operation.set_options(
    signer: cosigner,
    master_weight: master_weight
  )
end
client() click to toggle source
# File lib/mobius/client/blockchain/add_cosigner.rb, line 73
def client
  @client ||= Mobius::Client.horizon_client
end
cosigner() click to toggle source
# File lib/mobius/client/blockchain/add_cosigner.rb, line 62
def cosigner
  Stellar::Signer.new(
    key: Stellar::SignerKey.new(:signer_key_type_ed25519, cosigner_keypair.raw_public_key),
    weight: cosigner_weight
  )
end
set_thresholds_op() click to toggle source
# File lib/mobius/client/blockchain/add_cosigner.rb, line 54
def set_thresholds_op
  Stellar::Operation.set_options(
    high_threshold: master_weight,
    med_threshold: cosigner_weight,
    low_threshold: cosigner_weight
  )
end
tx() click to toggle source
# File lib/mobius/client/blockchain/add_cosigner.rb, line 36
def tx
  Stellar::Transaction.for_account(
    account: keypair,
    sequence: account.next_sequence_value
  ).tap do |txn|
    txn.operations << add_cosigner_op
    txn.operations << set_thresholds_op
    txn.fee *= txn.operations.size
  end
end