Class: SafeEthRuby::TransactionServiceApi

Inherits:
Object
  • Object
show all
Defined in:
lib/safe_eth_ruby/transaction_service_api.rb

Constant Summary collapse

VERSION =
"v1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain_id:, safe_address:) ⇒ TransactionServiceApi

Returns a new instance of TransactionServiceApi.



12
13
14
15
16
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 12

def initialize(chain_id:, safe_address:)
  (@network = network_name(chain_id)) || raise(ArgumentError, "Invalid network")
  @base_url = "https://safe-transaction-#{@network}.safe.global/api/#{VERSION}"
  @safe_address = safe_address
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 10

def base_url
  @base_url
end

#safe_addressObject (readonly)

Returns the value of attribute safe_address.



10
11
12
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 10

def safe_address
  @safe_address
end

Instance Method Details

#add_delegate(label:, delegate_address:, owner:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 25

def add_delegate(label:, delegate_address:, owner:)
  signature = sign_data(delegate_address, owner)
  post("delegates/", {
    safe: @safe_address,
    delegate: delegate_address,
    delegator: owner.address.to_s,
    label: label,
    signature: signature,
  })
end

#delegatesObject



18
19
20
21
22
23
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 18

def delegates
  response = get("delegates/?safe=#{@safe_address}")
  return response unless response[:error]

  response[:data]["results"]
end

#delete_delegate(delegate_address:, owner:) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 36

def delete_delegate(delegate_address:, owner:)
  signature = sign_data(delegate_address, owner)
  delete("delegates/#{delegate_address}/", {
    delegate: delegate_address,
    delegator: owner.address.to_s,
    signature: signature,
  })
end

#multisig_transaction(transaction) ⇒ Object



45
46
47
# File 'lib/safe_eth_ruby/transaction_service_api.rb', line 45

def multisig_transaction(transaction)
  post("safes/#{@safe_address}/multisig-transactions/", transaction)
end