Class: Bct::Apigm

Inherits:
Object
  • Object
show all
Defined in:
lib/bct/apigm.rb

Overview

classe para acesso dados blockchain EOS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(www: 'https://eos.greymass.com') ⇒ Apigm

Returns acesso dados blockchain EOS.

Parameters:

  • www (String) (defaults to: 'https://eos.greymass.com')

    base URL to use as a prefix for all requests



14
15
16
# File 'lib/bct/apigm.rb', line 14

def initialize(www: 'https://eos.greymass.com')
  @url = www
end

Instance Attribute Details

#urlString (readonly)

Returns base URL to use as a prefix for all requests.

Returns:

  • (String)

    base URL to use as a prefix for all requests



10
11
12
# File 'lib/bct/apigm.rb', line 10

def url
  @url
end

Instance Method Details

#account(**arg) ⇒ Hash

Returns dados & saldo duma carteira EOS.

Examples:

{
  account_name: '...',
  head_block_num: 141_391_122,
  head_block_time: '2020-09-11T16:05:51.000',
  privileged: false,
  last_code_update: '1970-01-01T00:00:00.000',
  created: '2018-06-09T13:14:37.000',
  core_liquid_balance: '1232.0228 EOS',
  ram_quota: 9548,
  net_weight: 10_001_142,
  cpu_weight: 10_001_144,
  net_limit: { used: 0, available: 1_066_648_346, max: 1_066_648_346 },
  cpu_limit: { used: 338, available: 88_498, max: 88_836 },
  ram_usage: 3574,
  permissions: [
    {
      perm_name: 'active',
      parent: 'owner',
      required_auth: {
        threshold: 1, keys: [{ key: 'EOS...', weight: 1 }], accounts: [], waits: []
      }
    },
    {
      perm_name: 'owner',
      parent: '',
      required_auth: {
        threshold: 1, keys: [{ key: 'EOS...', weight: 1 }], accounts: [], waits: []
      }
    }
  ],
  total_resources: { owner: '...', net_weight: '1000.1142 EOS', cpu_weight: '1000.1144 EOS', ram_bytes: 8148 },
  self_delegated_bandwidth: { from: '...', to: '...', net_weight: '1000.1142 EOS', cpu_weight: '1000.1144 EOS' },
  refund_request: nil,
  voter_info: {
    owner: '...',
    proxy: '...',
    producers: [],
    staked: 20_002_286,
    last_vote_weight: '17172913021904.12109375000000000',
    proxied_vote_weight: '0.00000000000000000',
    is_proxy: 0,
    flags1: 0,
    reserved2: 0,
    reserved3: '0.0000 EOS'
  },
  rex_info: nil
}

Parameters:

  • arg (Hash)

    argumentos trabalho

Options Hash (**arg):

  • :account_name (String)

    endereco carteira EOS

Returns:

  • (Hash)

    dados & saldo duma carteira EOS

Raises:



83
84
85
86
87
# File 'lib/bct/apigm.rb', line 83

def (**arg)
  raise(Erro, 'endereco tem de ser definido') if arg[:account_name].nil? || arg[:account_name].empty?

  get('/v1/chain/get_account', **arg)
end

#adapter<Symbol>

Returns adapter for the connection - default :net_http.

Returns:

  • (<Symbol>)

    adapter for the connection - default :net_http



19
20
21
# File 'lib/bct/apigm.rb', line 19

def adapter
  @adapter ||= Faraday.default_adapter
end

#all_tx(add, **arg) ⇒ Array<Hash>

Returns devolve lista de transacoes.

Examples:

{
  actions: [
    {
      account_action_seq: 964,
      action_trace: {
        account_ram_deltas: [],
        act: {
          account: 'voicebestapp',
          authorization: [
            { actor: 'thetruevoice', permission: 'active' },
            { actor: 'voicebestapp', permission: 'active' }
          ],
          data: { from: 'voicebestapp', memo: '...', quantity: '1.0001 MESSAGE', to: '...' },
          hex_data: '...',
          name: 'transfer'
        },
        action_ordinal: 10,
        block_num: 141_345_345,
        block_time: '2020-09-11T09:44:04.500',
        closest_unnotified_ancestor_action_ordinal: 5,
        context_free: false,
        creator_action_ordinal: 5,
        elapsed: 6,
        producer_block_id: '...',
        receipt: {
          abi_sequence: 1,
          act_digest: '...',
          auth_sequence: [['thetruevoice', 6_778_215], ['voicebestapp', 435_346]],
          code_sequence: 1,
          global_sequence: 233_283_589_258,
          receiver: '...',
          recv_sequence: 927
        },
        receiver: '...',
        trx_id: '...'
      },
      block_num: 141_345_345,
      block_time: '2020-09-11T09:44:04.500',
      global_action_seq: 233_283_589_258,
      irreversible: true
    },
    {}
  ],
  head_block_num: 141_721_698,
  last_irreversible_block: 141_721_371
}

Parameters:

  • add (String)

    endereco carteira EOS

  • arg (Hash)

    argumentos trabalho

Options Hash (**arg):

  • :account_name (String)

    endereco carteira EOS

  • :pos (Integer)

    posicao da primeira transacao a devolver

  • :offset (Integer)

    numero maximo transacoes a devolver

  • :filter (String)

    filtro a aplicar na resposta

  • :sort (String)

    ordenacao asc/desc

  • :after (String)

    time inicio “2020-09-13T13:44:03.105Z”

  • :before (String)

    time fim “2020-09-13T13:44:03.105Z”

  • :parent (Integer)

    transacao pai

Returns:

  • (Array<Hash>)

    devolve lista de transacoes

Raises:



147
148
149
150
151
# File 'lib/bct/apigm.rb', line 147

def all_tx(add, **arg)
  raise(Erro, 'endereco tem de ser definido') if add.nil? || add.empty?

  ledger(**arg.merge(account_name: add))
end

#conn<Faraday::Connection>

Returns connection object with an URL & adapter.

Returns:

  • (<Faraday::Connection>)

    connection object with an URL & adapter



24
25
26
27
28
29
30
# File 'lib/bct/apigm.rb', line 24

def conn
  @conn ||=
    Faraday.new(url: url) do |c|
      c.request(:url_encoded)
      c.adapter(adapter)
    end
end

#ledger(pos = 0, ary = [], **arg) ⇒ Array<Hash>

Returns lista das transacoes ligadas a uma carteira EOS.

Parameters:

  • pos (Integer) (defaults to: 0)

    posicao das transacoes a devolver

  • ary (Array<Hash>) (defaults to: [])

    lista acumuladora das transacoes a devolver

  • arg (Hash)

    argumentos trabalho

Options Hash (**arg):

  • :account_name (String)

    endereco carteira EOS

  • :pos (Integer)

    posicao da primeira transacao a devolver

  • :offset (Integer)

    numero maximo transacoes a devolver

  • :filter (String)

    filtro a aplicar na resposta

  • :sort (String)

    ordenacao asc/desc

  • :after (String)

    time inicio “2020-09-13T13:44:03.105Z”

  • :before (String)

    time fim “2020-09-13T13:44:03.105Z”

  • :parent (Integer)

    transacao pai

Returns:

  • (Array<Hash>)

    lista das transacoes ligadas a uma carteira EOS



158
159
160
161
162
163
164
# File 'lib/bct/apigm.rb', line 158

def ledger(pos = 0, ary = [], **arg)
  r = get('/v1/history/get_actions', **arg.merge(pos: pos, offset: 100))[:actions]
  ary += r
  r.count < 100 ? ary : ledger(pos + r.count, ary, **arg)
rescue StandardError
  ary
end