Class: Sequence::Transaction::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/sequence/transaction.rb

Overview

A configuration object for creating and submitting transactions.

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Builder

Returns a new instance of Builder.

Yields:

  • (_self)

Yield Parameters:



80
81
82
# File 'lib/sequence/transaction.rb', line 80

def initialize(&block)
  yield(self) if block
end

Instance Method Details

#actionsObject



85
86
87
# File 'lib/sequence/transaction.rb', line 85

def actions
  @actions ||= []
end

#add_action(opts = {}) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/sequence/transaction.rb', line 105

def add_action(opts = {})
  if opts[:amount].nil?
    raise ArgumentError, ':amount must be provided'
  end
  actions << opts
  self
end

#issue(amount:, flavor_id:, destination_account_id:, token_tags: {}, action_tags: {}) ⇒ Builder

Issue new tokens to a destination account.

Parameters:

  • amount (Integer)

    Amount of the flavor to be issued.

  • flavor_id (String)

    ID of the flavor to be issued.

  • destination_account_id (String)

    ID of the account receiving the flavor units.

  • token_tags (Hash) (defaults to: {})

    Tags to add to the receiving tokens.

  • action_tags (Hash) (defaults to: {})

    Tags to add to the action.

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/sequence/transaction.rb', line 134

def issue(
  amount:,
  flavor_id:,
  destination_account_id:,
  token_tags: {},
  action_tags: {}
)
  add_action(
    type: :issue,
    amount: amount,
    flavor_id: flavor_id,
    destination_account_id: ,
    token_tags: token_tags,
    action_tags: action_tags,
  )
end

#retire(amount:, flavor_id:, source_account_id:, filter: nil, filter_params: nil, action_tags: {}) ⇒ Builder

Take tokens from a source account and retire them.

Parameters:

  • amount (Integer)

    Amount of the flavor to be retired.

  • flavor_id (String)

    ID of the flavor to be retired.

  • source_account_id (String)

    ID of the account serving as the source of flavor units.

  • filter (String) (defaults to: nil)

    Token filter string. See https://dashboard.seq.com/docs/filters.

  • filter_params (Array<String|Integer>) (defaults to: nil)

    A list of parameter values for filter string (if needed).

  • action_tags (Hash) (defaults to: {})

    Tags to add to the action.

Returns:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/sequence/transaction.rb', line 206

def retire(
  amount:,
  flavor_id:,
  source_account_id:,
  filter: nil,
  filter_params: nil,
  action_tags: {}
)
  add_action(
    type: :retire,
    amount: amount,
    flavor_id: flavor_id,
    source_account_id: ,
    filter: filter,
    filter_params: filter_params,
    action_tags: action_tags,
  )
end

#to_hObject



95
96
97
# File 'lib/sequence/transaction.rb', line 95

def to_h
  { actions: actions, transaction_tags: transaction_tags }
end

#to_json(opts = nil) ⇒ Object



100
101
102
# File 'lib/sequence/transaction.rb', line 100

def to_json(opts = nil)
  to_h.to_json(opts)
end

#transaction_tagsObject



90
91
92
# File 'lib/sequence/transaction.rb', line 90

def transaction_tags
  @transaction_tags || {}
end

#transaction_tags=(tags) ⇒ Builder

Add tags to the transaction

Parameters:

  • tags (Hash)

    Transaction tags

Returns:



117
118
119
120
# File 'lib/sequence/transaction.rb', line 117

def transaction_tags=(tags)
  @transaction_tags = tags
  self
end

#transfer(amount:, flavor_id:, source_account_id:, destination_account_id:, filter: nil, filter_params: nil, token_tags: {}, action_tags: {}) ⇒ Builder

Move tokens from a source account to a destination account.

Parameters:

  • amount (Integer)

    Amount of the flavor to be transferred.

  • flavor_id (String)

    ID of the flavor to be transferred.

  • source_account_id (String)

    ID of the account serving as the source of flavor units.

  • destination_account_id (String)

    ID of the account receiving the flavor units.

  • filter (String) (defaults to: nil)

    Token filter string. See https://dashboard.seq.com/docs/filters.

  • filter_params (Array<String|Integer>) (defaults to: nil)

    A list of parameter values for filter string (if needed).

  • token_tags (Hash) (defaults to: {})

    Tags to add to the receiving tokens.

  • action_tags (Hash) (defaults to: {})

    Tags to add to the action.

Returns:



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/sequence/transaction.rb', line 169

def transfer(
  amount:,
  flavor_id:,
  source_account_id:,
  destination_account_id:,
  filter: nil,
  filter_params: nil,
  token_tags: {},
  action_tags: {}
)
  add_action(
    type: :transfer,
    amount: amount,
    flavor_id: flavor_id,
    source_account_id: ,
    destination_account_id: ,
    filter: filter,
    filter_params: filter_params,
    token_tags: token_tags,
    action_tags: action_tags,
  )
end