peatio-decredcoin 2.0.3 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ff1768afd86ac4684223228b7ce57fcec0a950836b0ae896cf2556706032af4
4
- data.tar.gz: bc5ff2e2ff1a16ae66f3672bcadd2051d2ad8a796b72c8b0e8abf950cc09bb22
3
+ metadata.gz: ba6527e3a8120dd3f82a8ae75e287680e0c1413af2eccee5492ecdc1dc9b29e8
4
+ data.tar.gz: 5d554617a8ebfff649c71ff516b838bc3858e2a09bbfe9f249fccdf8b8db6eab
5
5
  SHA512:
6
- metadata.gz: bfba25d6e9c25f3f68fd352d83d41464754b32f6018b22c8169153a38e0c2da9ba191a70aca8036158af263865b137e8e7f732de50817179c09662c6c123b1bd
7
- data.tar.gz: dc1651ddb8b157365b44f0d0d6a1e6a2194af9e5bd43da9bd7ff6adf706305be13a027d6b260e172698792a3f8b2753c1248f6e28df2b6c85663e8369b563904
6
+ metadata.gz: 67fd7d1622e46f75c0c694cc945b8394d36da57fcb23f9a41e1eae0a62741fcc79c9a6f6438daba8f8879748ec94de0aa666f858f2af2f36e7ae38c330c7c356
7
+ data.tar.gz: cec8773eae6c3022fd45679771a19c4ad0ecd4bf28a41062ccba891cb57ef9999b2e3b23f5a15da302c52c3155a325cc571ef9b82c583e8b393d776fbdc1493e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- peatio-decredcoin (2.0.2)
4
+ peatio-decredcoin (2.1.1)
5
5
  activesupport (~> 5.2.3)
6
6
  better-faraday (~> 1.0.5)
7
7
  faraday (~> 0.17)
@@ -19,8 +19,8 @@ module Peatio
19
19
  def fetch_block!(block_number)
20
20
  block_hash = client.json_rpc(:getblockhash, [block_number])
21
21
 
22
- client.json_rpc(:getblock, [block_hash, 2])
23
- .fetch('tx').each_with_object([]) do |tx, txs_array|
22
+ client.json_rpc(:getblock, [block_hash, true, true])
23
+ .fetch('rawtx').each_with_object([]) do |tx, txs_array|
24
24
  txs = build_transaction(tx).map do |ntx|
25
25
  Peatio::Transaction.new(ntx.merge(block_number: block_number))
26
26
  end
@@ -53,12 +53,9 @@ module Peatio
53
53
  private
54
54
 
55
55
  def build_transaction(tx_hash)
56
- tx_hash.fetch('vout')
57
- .select do |entry|
58
- entry.fetch('value').to_d > 0 &&
59
- entry['scriptPubKey'].has_key?('addresses')
60
- end
61
- .each_with_object([]) do |entry, formatted_txs|
56
+ tx_hash.fetch('vout').select do |entry|
57
+ entry.fetch('value').to_d > 0 && entry['scriptPubKey'].has_key?('addresses')
58
+ end.each_with_object([]) do |entry, formatted_txs|
62
59
  no_currency_tx =
63
60
  { hash: tx_hash['txid'], txout: entry['n'],
64
61
  to_address: entry['scriptPubKey']['addresses'][0],
@@ -1,5 +1,5 @@
1
1
  module Peatio
2
2
  module Decredcoin
3
- VERSION = "2.0.3".freeze
3
+ VERSION = "3.0.1".freeze
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ module Peatio
18
18
 
19
19
  @wallet = @settings.fetch(:wallet) do
20
20
  raise Peatio::Wallet::MissingSettingError, :wallet
21
- end.slice(:uri, :address)
21
+ end.slice(:uri, :address, :passphrase)
22
22
 
23
23
  @currency = @settings.fetch(:currency) do
24
24
  raise Peatio::Wallet::MissingSettingError, :currency
@@ -31,14 +31,13 @@ module Peatio
31
31
  raise Peatio::Wallet::ClientError, e
32
32
  end
33
33
 
34
+ # create a transaction
34
35
  def create_transaction!(transaction, options = {})
36
+ unlock_wallet!(options[:timeout])
35
37
  txid = client.json_rpc(:sendtoaddress,
36
38
  [
37
39
  transaction.to_address,
38
- transaction.amount,
39
- '',
40
- '',
41
- options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
40
+ transaction.amount.to_f
42
41
  ])
43
42
  transaction.hash = txid
44
43
  transaction
@@ -46,15 +45,30 @@ module Peatio
46
45
  raise Peatio::Wallet::ClientError, e
47
46
  end
48
47
 
49
- def load_balance!
50
- client.json_rpc(:getbalance).to_d
48
+ def load_balance!(account_name = 'default')
49
+ response = client.json_rpc(:getbalance)
50
+ account = response['balances'].find { |k| k['accountname'].eql? account_name }
51
51
 
52
+ raise Decredcoin::Client::Error.new 'account does not exists' unless account
53
+
54
+ account['total'].to_d
52
55
  rescue Decredcoin::Client::Error => e
53
56
  raise Peatio::Wallet::ClientError, e
54
57
  end
55
58
 
56
59
  private
57
60
 
61
+ # unlock wallet for 15 seconds
62
+ def unlock_wallet!(timeout = 15)
63
+ client.json_rpc(:walletpassphrase,
64
+ [
65
+ @wallet.fetch(:passphrase),
66
+ timeout
67
+ ])
68
+ rescue Decredcoin::Client::Error => e
69
+ raise Peatio::Wallet::ClientError, e
70
+ end
71
+
58
72
  def client
59
73
  uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
60
74
  @client ||= Client.new(uri)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peatio-decredcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anuj Dhiman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport