Skip to content

Commit

Permalink
Merge pull request #70 from piotr-iohk/mint_burn
Browse files Browse the repository at this point in the history
Minting/burning form init
  • Loading branch information
piotr-iohk authored Apr 28, 2022
2 parents 6e922ec + 3a1095c commit a674be5
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 194 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'cardano_wallet', '~> 0.3.18'
gem 'cardano_wallet', '~> 0.3.20'
# gem 'cardano_wallet', path: "~/wb/cardano_wallet"
gem 'sys-proctable', '~> 1.2.3'
gem 'docopt', '~> 0.6.1'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
xpath (~> 3.2)
cardano_wallet (0.3.18)
cardano_wallet (0.3.20)
httparty (~> 0.18.0)
chartkick (3.4.0)
codecov (0.2.9)
Expand Down Expand Up @@ -81,7 +81,7 @@ PLATFORMS
DEPENDENCIES
bip_mnemonic (~> 0.0.4)
capybara
cardano_wallet (~> 0.3.18)
cardano_wallet (~> 0.3.20)
chartkick (~> 3.4.0)
codecov (~> 0.2.8)
docopt (~> 0.6.1)
Expand Down
200 changes: 128 additions & 72 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


before do
@timeout = 600
@timeout = 3600
session[:opt] ||= {port: 8090, timeout: @timeout}
@cw ||= CardanoWallet.new session[:opt]
session[:opt] ||= @cw.opt
Expand Down Expand Up @@ -133,11 +133,13 @@
post "/get-pub-key" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
hash = params[:hash] == 'true' ? { hash: true } : {}

begin
pub_key = @cw.shelley.keys.get_public_key(params[:wid],
params[:role],
params[:index])
params[:index],
hash)
rescue
session[:error] = "Make sure parameters are valid. "
redirect "/get-pub-key"
Expand All @@ -148,10 +150,93 @@
:role => params[:role],
:index => params[:index],
:pub_key => pub_key,
:hash => nil
:hash => params[:hash]
} }
end

get "/get-policy-key" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
params[:wid] ? wid = params[:wid] : wid = wallets.first['id']
erb :form_get_policy_key, { :locals => { :wallets => wallets,
:wid => wid,
:policy_key => nil,
:hash => nil } }
end

post "/get-policy-key" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
hash = params[:hash] == 'true' ? { hash: true } : {}
begin
policy_key = @cw.shelley.keys.get_policy_key(params[:wid], hash)
rescue
session[:error] = "Make sure parameters are valid. "
redirect "/get-policy-key"
end
handle_api_err policy_key, session
erb :form_get_policy_key, { :locals => { :wallets => wallets,
:wid => params[:wid],
:policy_key => policy_key,
:hash => params[:hash]
} }
end

get "/create-policy-id" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
params[:wid] ? wid = params[:wid] : wid = wallets.first['id']
erb :form_create_policy_id, { :locals => { :wallets => wallets,
:wid => wid,
:policy_script_template => nil,
:policy_id => nil } }
end

post "/create-policy-id" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
begin
policy_script_template = JSON.parse(params[:mint_policy_script].strip)
rescue
policy_script_template = params[:mint_policy_script]
end
policy_id = @cw.shelley.keys.create_policy_id(params[:wid], policy_script_template)
handle_api_err policy_id, session
erb :form_create_policy_id, { :locals => { :wallets => wallets,
:wid => params[:wid],
:policy_script_template => params[:mint_policy_script],
:policy_id => policy_id } }
end

get "/create-policy-key" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
params[:wid] ? wid = params[:wid] : wid = wallets.first['id']
erb :form_create_policy_key, { :locals => { :wallets => wallets,
:wid => wid,
:pass => 'Secure Passphrase',
:policy_key => nil,
:hash => nil } }
end

post "/create-policy-key" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
hash = params[:hash] == 'true' ? { hash: true } : {}
begin
policy_key = @cw.shelley.keys.create_policy_key(params[:wid], params[:pass], hash)
rescue
session[:error] = "Make sure parameters are valid. "
redirect "/create-policy-key"
end
handle_api_err policy_key, session
erb :form_create_policy_key, { :locals => { :wallets => wallets,
:wid => params[:wid],
:pass => params[:pass],
:policy_key => policy_key,
:hash => params[:hash] } }
end

get "/sign-metadata" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
Expand Down Expand Up @@ -348,12 +433,12 @@
post "/shared-get-pub-key" do
wallets = @cw.shared.wallets.list
handle_api_err wallets, session

hash = params[:hash] == 'true' ? { hash: true } : {}
begin
pub_key = @cw.shared.keys.get_public_key(params[:wid],
params[:role],
params[:index],
{'hash' => params[:hash]})
hash)
rescue
session[:error] = "Make sure parameters are valid. "
redirect "/shared-get-pub-key"
Expand Down Expand Up @@ -384,7 +469,6 @@
redirect "/shared-wallets/#{params[:wal_id]}"
end


get "/shared-wallets/:wal_id/patch-delegation" do
wal = @cw.shared.wallets.get params[:wal_id]
handle_api_err wal, session
Expand Down Expand Up @@ -513,70 +597,6 @@
end

# SHELLEY WALLETS

get "/mint-to-address" do
wallets = @cw.shelley.wallets.list
handle_api_err(wallets, session)

erb :form_mint_to_multi_address, { :locals => { :wallets => wallets,
:asset_name => nil,
:asset => nil } }
end

post "/mint-to-address" do
wallets = @cw.shelley.wallets.list
handle_api_err(wallets, session)

case params['operation']
when 'mint_to_self'
my_address = @cw.shelley.addresses.list(params['wid_src'], {state: "unused"}).first['id']
mint_burn = [
{
"monetary_policy_index" => params['monetary_policy_index'],
"asset_name" => params['asset_name'].unpack('H*').first,
"operation" => {
"mint" => {
"receiving_address" => my_address,
"amount" => {
"quantity" => params['amount'].to_i,
"unit" => "assets"
}
}
}
}
]


when 'mint'
mint_burn = parse_addr_amt_mint(params['addr_amt'],
params['monetary_policy_index'],
params['asset_name'].unpack('H*').first)
when 'burn'
mint_burn = [
{
"monetary_policy_index" => params['monetary_policy_index'],
"asset_name" => params['asset_name'].unpack('H*').first,
"operation" => {
"burn" => { "quantity" => params['amount'].to_i,
"unit": "assets" }
}
}
]
end
# operation = JSON.parse(params['operation'])
m = parse_metadata(params[:metadata])
params[:ttl] == '' ? ttl = nil : ttl = params[:ttl].to_i
mint_or_burn = @cw.shelley.assets.mint(params['wid_src'],
mint_burn,
params['pass'],
m,
ttl
)
handle_api_err(mint_or_burn, session)

erb :tx_details, { :locals => { :tx => mint_or_burn, :wid => params['wid_src'] } }
end

get "/wallets-get-assets" do
wallets = @cw.shelley.wallets.list
handle_api_err(wallets, session)
Expand Down Expand Up @@ -980,6 +1000,43 @@
]
end
end
if params[:mint_check]
mint = {}
if params[:mint_action] == 'mint'
addr = params[:mint_receiving_address].strip
if addr.empty?
mint[:operation] = {
'mint' => { 'quantity' => params[:mint_amount].to_i }
}
else
mint[:operation] = {
'mint' => { 'receiving_address' => addr,
'quantity' => params[:mint_amount].to_i }
}
end
end
if params[:mint_action] == 'burn'
mint[:operation] = {
'burn' => { 'quantity' => params[:mint_amount].to_i }
}
end

# policy script is either script or just string specifying cosigner
begin
script = JSON.parse(params[:mint_policy_script].strip)
rescue
script = params[:mint_policy_script]
end
mint[:policy_script_template] = script

if params[:mint_hex] == 'true'
mint[:asset_name] = params[:mint_asset_name]
else
# Encode mint_asset_name to hex
mint[:asset_name] = params[:mint_asset_name].unpack("H*").first
end
mint_burn = [mint]
end

if params[:validity_interval_check]
validity_interval = {}
Expand Down Expand Up @@ -1009,7 +1066,7 @@
withdrawal,
metadata,
delegations,
mint = nil,
mint_burn,
validity_interval)
handle_api_err tx, session
decoded_tx = @cw.shelley.transactions.decode(wid, tx['transaction'])
Expand Down Expand Up @@ -1068,7 +1125,6 @@
erb :tx_details, { :locals => { :tx => tx, :wid => wid} }
end


get "/wallets-transactions" do
query = toListTransactionsQuery(params)
r = @cw.shelley.transactions.list(params[:wid], query)
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.5"

services:
cardano-node:
image: inputoutput/cardano-node:1.30.1
image: inputoutput/cardano-node:1.34.1
environment:
NETWORK:
volumes:
Expand All @@ -11,7 +11,7 @@ services:
restart: on-failure

cardano-wallet:
image: inputoutput/cardano-wallet:2021.11.11
image: inputoutput/cardano-wallet:2022.4.27
volumes:
- wallet-${NETWORK}-db:/wallet-db
- node-ipc:/ipc
Expand All @@ -28,7 +28,7 @@ services:
restart: on-failure

icarus:
image: piotrstachyra/icarus:v2021-11-11
image: piotrstachyra/icarus:v2022-04-27
network_mode: "host"
restart: on-failure

Expand Down
32 changes: 31 additions & 1 deletion helpers/app_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Helpers
module App
def version
'v2021-11-11' #version
'v2022-04-27' #version
end

def is_connected?(w)
Expand Down Expand Up @@ -677,6 +677,36 @@ def render_shared_wallet_create_form_part
)
end

def render_policy_script_template_form_part(policy_script = nil)
%(
<div class="form-group">
<label for="mint_policy_script">Policy Script Template</label>
<textarea class="form-control" name="mint_policy_script" id="mint_policy_script" rows="5">#{policy_script}</textarea>
<small id="help_pay" class="form-text text-muted">
<details>
<summary>Examplary template</summary>
<pre>
cosigner#0
{ "all": [ "cosigner#0" ] }
{ "any": [ "cosigner#0" ] }
{ "some": {"at_least": 1, "from": [ "cosigner#0" ]} }
{ "all":
[ "cosigner#0",
{ "active_from": 120 }
]
}
</pre>
</details>
</small>
</div>
)
end

def render_danger(text)
"<span class='badge badge-danger'>#{text}</span>"
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/make_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -euo pipefail

GIT_TAG="v2021-11-11"
NODE_TAG="1.30.1"
GIT_TAG="v2022-04-27"
NODE_TAG="1.34.1"

DOCKER_TAG=`echo "${GIT_TAG##v}" | sed -e s/-0/-/g -e s/-/./g`

Expand Down
Loading

0 comments on commit a674be5

Please sign in to comment.