Skip to content

Commit

Permalink
redeem rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Jul 31, 2020
1 parent 8232b1f commit 97981a8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docker-compose-shelley.yml
Expand Up @@ -18,7 +18,7 @@ services:
- ${NODE_CONFIG_PATH}:/config
ports:
- 8090:8090
command: serve --staging /config/${NETWORK}-byron-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
command: serve --testnet /config/${NETWORK}-byron-genesis.json --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0
restart: on-failure

volumes:
Expand Down
41 changes: 29 additions & 12 deletions lib/cardano_wallet/shelley.rb
Expand Up @@ -195,17 +195,26 @@ def list(wid, q = {})
# @param wid [String] source wallet id
# @param passphrase [String] source wallet's passphrase
# @param payments [Hash] addres, amount pair
# @param q [Hash] query param (currently only withdrawRewards = true | false)
# @param withdrawal [Strin or Array] 'self' or mnemonic sentence
#
# @example
# create(wid, passphrase, {addr1: 1000000}, q)
def create(wid, passphrase, payments, q = {})
# create(wid, passphrase, {addr1: 1000000}, 'self')
def create(wid, passphrase, payments, withdrawal = nil)
payments_formatted = Utils.format_payments(payments)
q.empty? ? query = '' : query = Utils.to_query(q)
self.class.post("/wallets/#{wid}/transactions#{query}",
:body => { :payments => payments_formatted,
:passphrase => passphrase
}.to_json,

if withdrawal
payload = { :payments => payments_formatted,
:passphrase => passphrase,
:withdrawal => withdrawal,
}
else
payload = { :payments => payments_formatted,
:passphrase => passphrase
}
end

self.class.post("/wallets/#{wid}/transactions",
:body => payload.to_json,
:headers => { 'Content-Type' => 'application/json' } )
end

Expand All @@ -214,11 +223,19 @@ def create(wid, passphrase, payments, q = {})
#
# @example
# payment_fees(wid, {addr1: 1000000})
def payment_fees(wid, payments, q = {})
def payment_fees(wid, payments, withdrawal = nil)
payments_formatted = Utils.format_payments(payments)
q.empty? ? query = '' : query = Utils.to_query(q)
self.class.post("/wallets/#{wid}/payment-fees#{query}",
:body => { :payments => payments_formatted }.to_json,

if withdrawal
payload = { :payments => payments_formatted,
:withdrawal => withdrawal
}
else
payload = { :payments => payments_formatted }
end

self.class.post("/wallets/#{wid}/payment-fees",
:body => payload.to_json,
:headers => { 'Content-Type' => 'application/json' } )
end

Expand Down
10 changes: 5 additions & 5 deletions spec/shelley_spec.rb
Expand Up @@ -208,15 +208,15 @@
end
end

it "I can send transaction using 'withdrawRewards' flag and funds are received", :nightly => true do
it "I can send transaction using 'withdrawal' flag and funds are received", :nightly => true do
amt = 1000000
wid = create_fixture_shelley_wallet
wait_for_shelley_wallet_to_sync(wid)
target_id = create_shelley_wallet
wait_for_shelley_wallet_to_sync(target_id)
address = SHELLEY.addresses.list(target_id)[0]['id']

tx_sent = SHELLEY.transactions.create(wid, PASS, {address => amt}, {withdrawRewards: true})
tx_sent = SHELLEY.transactions.create(wid, PASS, {address => amt}, 'self')
expect(tx_sent.code).to eq 202

eventually "Funds are on target wallet: #{target_id}" do
Expand All @@ -243,8 +243,8 @@
address = SHELLEY.addresses.list(target_id)[0]['id']
txs = SHELLEY.transactions

tx_sent = txs.create(id, PASS, {address => 1000000}, {withdrawRewards: true})
expect(tx_sent).to include "not_enough_money"
tx_sent = txs.create(id, PASS, {address => 1000000}, 'self')
expect(tx_sent).to include "withdrawal_not_worth"
expect(tx_sent.code).to eq 403
end

Expand All @@ -259,7 +259,7 @@
expect(fees).to include "not_enough_money"
expect(fees.code).to eq 403

fees = txs.payment_fees(id, {address => 1000000}, {withdrawRewards: true})
fees = txs.payment_fees(id, {address => 1000000}, 'self')
expect(fees).to include "not_enough_money"
expect(fees.code).to eq 403
end
Expand Down

0 comments on commit 97981a8

Please sign in to comment.