Module: NanoRpc::WalletHelper

Includes:
ApplicationHelper
Included in:
Wallet
Defined in:
lib/nano_rpc/helpers/wallet_helper.rb

Instance Method Summary collapse

Instance Method Details

#account_work(account:) ⇒ Object



5
6
7
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 5

def (account:)
  work_get(account: ).work
end

#account_work_set(account:, work:) ⇒ Object Also known as: set_account_work



144
145
146
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 144

def (account:, work:)
  work_set(account: , work: work).success == ''
end

#accountsObject



9
10
11
12
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 9

def accounts
  return [] unless .accounts.size.positive?
  NanoRpc::Accounts.new(.accounts, node: node)
end

#add_key(key:, work: true) ⇒ Object



14
15
16
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 14

def add_key(key:, work: true)
  wallet_add(key: key, work: work).
end

#add_watch(accounts:) ⇒ Object



18
19
20
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 18

def add_watch(accounts:)
  wallet_add_watch(accounts: accounts).success == ''
end

#balanceObject



22
23
24
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 22

def balance
  wallet_info.balance
end

#balances(threshold: nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 26

def balances(threshold: nil)
  wallet_balances(threshold: threshold)
    .balances
    .each_with_object({}) do |(k, v), hash|
      hash[k] = v['balance'].to_i
    end
end

#begin_paymentObject



34
35
36
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 34

def begin_payment
  payment_begin.
end

#change_password(new_password:) ⇒ Object



38
39
40
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 38

def change_password(new_password:)
  password_change(password: new_password).changed == 1
end

#change_seed(new_seed:, count: 0) ⇒ Object



42
43
44
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 42

def change_seed(new_seed:, count: 0)
  wallet_change_seed(seed: new_seed, count: count).success == ''
end

#contains?(account:) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 46

def contains?(account:)
  wallet_contains(account: ).exists == 1
end

#create_account(work: true) ⇒ Object



50
51
52
53
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 50

def (work: true)
  address = (work: work).
  NanoRpc::Account.new(address, node: node)
end

#create_accounts(count:, work: true) ⇒ Object



55
56
57
58
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 55

def create_accounts(count:, work: true)
  addresses = accounts_create(count: count, work: work).accounts
  NanoRpc::Accounts.new(addresses, node: node)
end

#destroyObject



60
61
62
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 60

def destroy
  wallet_destroy.destroyed == 1
end

#enter_password(password:) ⇒ Object Also known as: unlock



64
65
66
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 64

def enter_password(password:)
  password_enter(password: password).valid == 1
end

#exportObject



69
70
71
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 69

def export
  NanoRpc::Response.new(JSON[wallet_export.json])
end

#frontiersObject



73
74
75
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 73

def frontiers
  wallet_frontiers.frontiers
end

#history(modified_since: 0) ⇒ Object



77
78
79
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 77

def history(modified_since: 0)
  wallet_history(modified_since: modified_since).history
end

#init_paymentObject



81
82
83
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 81

def init_payment
  payment_init.status == 'Ready'
end

#ledgerObject



85
86
87
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 85

def ledger
  wallet_ledger.accounts
end

#locked?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 89

def locked?
  wallet_locked.locked == 1
end

#move_accounts(to:, accounts:) ⇒ Object



93
94
95
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 93

def move_accounts(to:, accounts:)
  (wallet: to, source: id, accounts: accounts).moved == 1
end

#password_valid?(password:) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 97

def password_valid?(password:)
  password_valid(password: password).valid == 1
end

#pending_balanceObject Also known as: balance_pending



101
102
103
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 101

def pending_balance
  wallet_info.pending
end

#pending_balances(threshold: nil) ⇒ Object Also known as: balances_pending



106
107
108
109
110
111
112
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 106

def pending_balances(threshold: nil)
  wallet_balances(threshold: threshold)
    .balances
    .each_with_object({}) do |(k, v), hash|
      hash[k] = v['pending'].to_i
    end
end

#pending_blocks(count:, threshold: nil, source: nil, include_active: nil) ⇒ Object Also known as: blocks_pending



115
116
117
118
119
120
121
122
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 115

def pending_blocks(count:, threshold: nil, source: nil, include_active: nil)
  wallet_pending(
    count: count,
    threshold: threshold,
    source: source,
    include_active: include_active
  ).blocks
end

#receive_block(account:, block:) ⇒ Object



125
126
127
128
129
130
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 125

def receive_block(account:, block:)
  receive(
    account: ,
    block: block
  ).block
end

#remove_account(account:) ⇒ Object



132
133
134
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 132

def (account:)
  (account: ).removed == 1
end

#representativeObject



136
137
138
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 136

def representative
  wallet_representative.representative
end

#representative_set(representative:) ⇒ Object Also known as: set_representative



149
150
151
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 149

def representative_set(representative:)
  wallet_representative_set(representative: representative).set == 1
end

#republish(count:) ⇒ Object



140
141
142
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 140

def republish(count:)
  wallet_republish(count: count).blocks
end

#send_nano(from:, to:, amount:, id: nil, work: nil) ⇒ Object Also known as: send_transaction



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 154

def send_nano(from:, to:, amount:, id: nil, work: nil)
  from = from.respond_to?(:address) ? from.address : from
  to = to.respond_to?(:address) ? to.address : to
  send_currency(
    source: from,
    destination: to,
    amount: amount,
    id: id,
    work: work
  ).block
end

#workObject



167
168
169
# File 'lib/nano_rpc/helpers/wallet_helper.rb', line 167

def work
  wallet_work_get.works
end