Module: TezosClient::RpcInterface::Contracts

Included in:
TezosClient::RpcInterface
Defined in:
lib/tezos_client/rpc_interface/contracts.rb

Instance Method Summary collapse

Instance Method Details

#balance(contract_id) ⇒ Object



17
18
19
20
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 17

def balance(contract_id)
  res = get("#{contract_link(contract_id)}/balance")
  res.to_i.from_satoshi
end

#big_map_value(big_map_id:, key:, key_type:) ⇒ Object



48
49
50
51
52
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 48

def big_map_value(big_map_id:, key:, key_type:)
  expr_key = encode_script_expr(data: key, type: key_type)

  get "/chains/main/blocks/head/context/big_maps/#{big_map_id}/#{expr_key}"
end

#contract_big_maps(contract_address) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 54

def contract_big_maps(contract_address)
  contract_storage = contract_storage(contract_address)
  storage_type = contract_storage_type(contract_address)

  TezosClient::Tools::FindBigMapsInStorage.run!(
    storage: contract_storage,
    storage_type: storage_type
  )
end

#contract_counter(contract_id) ⇒ Object



22
23
24
25
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 22

def contract_counter(contract_id)
  res = get("#{contract_link(contract_id)}/counter")
  res.to_i
end

#contract_detail(contract_id) ⇒ Object



13
14
15
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 13

def contract_detail(contract_id)
  get contract_link(contract_id)
end


9
10
11
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 9

def contract_link(contract_id)
  "/chains/main/blocks/head/context/contracts/#{contract_id}"
end

#contract_manager_key(contract_id) ⇒ Object



27
28
29
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 27

def contract_manager_key(contract_id)
  get "#{contract_link(contract_id)}/manager_key"
end

#contract_storage(contract_id) ⇒ Object



36
37
38
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 36

def contract_storage(contract_id)
  get "#{contract_link(contract_id)}/storage"
end

#contract_storage_type(contract_id) ⇒ Object



31
32
33
34
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 31

def contract_storage_type(contract_id)
  contract = contract_detail(contract_id)
  contract[:script][:code].find { |elem| elem[:prim] == "storage" }[:args].first
end

#entrypoint(contract_id, entrypoint) ⇒ Object



44
45
46
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 44

def entrypoint(contract_id, entrypoint)
  get("#{contract_link(contract_id)}/entrypoints/#{entrypoint}")
end

#entrypoints(contract_id) ⇒ Object



40
41
42
# File 'lib/tezos_client/rpc_interface/contracts.rb', line 40

def entrypoints(contract_id)
  get("#{contract_link(contract_id)}/entrypoints")
end