Class: Bluzelle::Swarm::Cosmos

Inherits:
Object
  • Object
show all
Includes:
Constants, Utils
Defined in:
lib/bluzelle/swarm/cosmos.rb

Constant Summary

Constants included from Constants

Constants::BLOCK_TIME_IN_SECONDS, Constants::BROADCAST_RETRY_SECONDS, Constants::PATH, Constants::PREFIX, Constants::TOKEN_NAME, Constants::TX_COMMAND

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

bech32_convert_bits, bech32_encode, bip32_from_seed, bip39_mnemonic_to_seed, compressed_pub_key, convert_lease, create_ec_pair, decode_json, ecdsa_sign, encode_json, extract_error_message, get_address, get_ec_private_key, get_ec_public_key_from_priv, hex_to_bin, make_random_string, open_key, rmd_160_digest, sha_256_digest, sort_hash, stringify_keys, to_base64, to_bytes, validate_address

Constructor Details

#initialize(options = {}) ⇒ Cosmos

Returns a new instance of Cosmos.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bluzelle/swarm/cosmos.rb', line 17

def initialize(options = {})
  @mnemonic = options[:mnemonic]
  @chain_id = options[:chain_id]
  @endpoint = options[:endpoint]
  @account_info = {}

  @private_key = get_ec_private_key(@mnemonic)
  @address = address_from_mnemonic

  
end

Instance Attribute Details

#account_infoObject

Returns the value of attribute account_info.



15
16
17
# File 'lib/bluzelle/swarm/cosmos.rb', line 15

def 
  @account_info
end

#addressObject (readonly)

Returns the value of attribute address.



14
15
16
# File 'lib/bluzelle/swarm/cosmos.rb', line 14

def address
  @address
end

#chain_idObject (readonly)

Returns the value of attribute chain_id.



14
15
16
# File 'lib/bluzelle/swarm/cosmos.rb', line 14

def chain_id
  @chain_id
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



14
15
16
# File 'lib/bluzelle/swarm/cosmos.rb', line 14

def endpoint
  @endpoint
end

#mnemonicObject (readonly)

Returns the value of attribute mnemonic.



14
15
16
# File 'lib/bluzelle/swarm/cosmos.rb', line 14

def mnemonic
  @mnemonic
end

Instance Method Details

#query(endpoint) ⇒ Object



29
30
31
# File 'lib/bluzelle/swarm/cosmos.rb', line 29

def query(endpoint)
  Request.execute(method: 'get', url: "#{@endpoint}/#{endpoint}")
end

#send_transaction(method, endpoint, data, gas_info) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bluzelle/swarm/cosmos.rb', line 33

def send_transaction(method, endpoint, data, gas_info)
  txn = Transaction.new(method, endpoint, data)
  txn.set_gas(gas_info)

  # fetch skeleton
  skeleton = fetch_txn_skeleton(txn)
  # set gas
  skeleton = update_gas(txn, skeleton)
  # sort
  skeleton = sort_hash(skeleton)

  broadcast_transaction(Transaction.new('post', TX_COMMAND, skeleton))
end