Module: TezosClient::RpcInterface::Helper

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

Instance Method Summary collapse

Instance Method Details

#activate_account_operation(args) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/tezos_client/rpc_interface/helper.rb', line 57

def (args)
  {
    kind: "activate_account",
    pkh: args.fetch(:pkh),
    secret: args.fetch(:secret)
  }
end

#broadcast_operation(data) ⇒ Object



131
132
133
# File 'lib/tezos_client/rpc_interface/helper.rb', line 131

def broadcast_operation(data)
  post("injection/operation?chain=main", data)
end

#contents(args) ⇒ Object



135
136
137
138
# File 'lib/tezos_client/rpc_interface/helper.rb', line 135

def contents(args)
  operation = operation(args)
  (operation.is_a?(Array)) ? operation : [operation]
end

#forge_operation(args) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/tezos_client/rpc_interface/helper.rb', line 123

def forge_operation(args)
  content = {
    branch: args.fetch(:branch),
    contents: contents(args)
  }
  post("chains/main/blocks/head/helpers/forge/operations", content)
end

#operation(args) ⇒ Object



77
78
79
80
# File 'lib/tezos_client/rpc_interface/helper.rb', line 77

def operation(args)
  operation_kind = args.fetch(:operation_kind) { raise ArgumentError, ":operation_kind argument missing" }
  send("#{operation_kind}_operation", args)
end

#origination_operation(args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tezos_client/rpc_interface/helper.rb', line 38

def origination_operation(args)
  operation = {
    kind: "origination",
    delegatable: args.fetch(:delegatable),
    spendable: args.fetch(:spendable),
    balance: args.fetch(:amount).to_satoshi.to_s,
    source: args.fetch(:from),
    gas_limit: args.fetch(:gas_limit).to_satoshi.to_s,
    storage_limit: args.fetch(:storage_limit).to_satoshi.to_s,
    counter: args.fetch(:counter).to_s,
    fee: args.fetch(:fee).to_satoshi.to_s,
    managerPubkey: args.fetch(:manager)
  }

  operation[:script] = args[:script] if args[:script]
  operation
end

#preapply_operation(args) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/tezos_client/rpc_interface/helper.rb', line 100

def preapply_operation(args)
  content = {
    protocol: args.fetch(:protocol),
    branch: args.fetch(:branch),
    contents: contents(args),
    signature: args.fetch(:signature)
  }

  res = post("chains/main/blocks/head/helpers/preapply/operations",
             [content])
  res[0]["contents"][0]
end

#reveal_operation(args) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tezos_client/rpc_interface/helper.rb', line 65

def reveal_operation(args)
  {
    kind: "reveal",
    source: args.fetch(:from),
    fee: args.fetch(:fee).to_satoshi.to_s,
    counter: args.fetch(:counter).to_s,
    gas_limit: args.fetch(:gas_limit).to_satoshi.to_s,
    storage_limit: args.fetch(:storage_limit).to_satoshi.to_s,
    public_key: args.fetch(:public_key)
  }
end

#run_operation(args) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/tezos_client/rpc_interface/helper.rb', line 113

def run_operation(args)
  content = {
    branch: args.fetch(:branch),
    contents: contents(args),
    signature: args.fetch(:signature)
  }
  res = post("chains/main/blocks/head/helpers/scripts/run_operation", content)
  res["contents"][0]
end

#transaction_operation(args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tezos_client/rpc_interface/helper.rb', line 8

def transaction_operation(args)
  operation = {
    kind: "transaction",
    amount: args.fetch(:amount).to_satoshi.to_s,
    source: args.fetch(:from),
    destination: args.fetch(:to),
    gas_limit: args.fetch(:gas_limit).to_satoshi.to_s,
    storage_limit: args.fetch(:storage_limit).to_satoshi.to_s,
    counter: args.fetch(:counter).to_s,
    fee: args.fetch(:fee).to_satoshi.to_s
  }
  operation[:parameters] = args[:parameters] if args[:parameters]
  operation
end

#transactions_operation(args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tezos_client/rpc_interface/helper.rb', line 23

def transactions_operation(args)
  args[:amounts].map.with_index do |(destination, amount), index|
    {
      kind: "transaction",
      amount: amount.to_satoshi.to_s,
      source: args.fetch(:from),
      destination: destination,
      gas_limit: args.fetch(:gas_limit).to_satoshi.to_s,
      storage_limit: args.fetch(:storage_limit).to_satoshi.to_s,
      counter: (args.fetch(:counter) + index).to_s,
      fee: args.fetch(:fee).to_satoshi.to_s
    }
  end
end