From 6790197bb67e9252373f23724a3b971ccf8a05a6 Mon Sep 17 00:00:00 2001 From: njank Date: Mon, 13 Sep 2021 02:02:58 +0700 Subject: [PATCH] init dump --- ipfs/ipfs.ps1 | 30 +++++++++++ mint/mint.ps1 | 107 ++++++++++++++++++++++++++++++++++++++ payskey/1getpayskey.cmd | 10 ++++ payskey/2getaddresses.cmd | 9 ++++ policy/getpolicy.ps1 | 49 +++++++++++++++++ 5 files changed, 205 insertions(+) create mode 100644 ipfs/ipfs.ps1 create mode 100644 mint/mint.ps1 create mode 100644 payskey/1getpayskey.cmd create mode 100644 payskey/2getaddresses.cmd create mode 100644 policy/getpolicy.ps1 diff --git a/ipfs/ipfs.ps1 b/ipfs/ipfs.ps1 new file mode 100644 index 0000000..82b4667 --- /dev/null +++ b/ipfs/ipfs.ps1 @@ -0,0 +1,30 @@ +$blockfrostApiKey="xxxxxxxxxxxxxxxxxxxxxx" +$curlExe = 'C:\Program Files\xxxxxxxxxxxx\mingw64\bin\curl.exe' +$data = @( + [pscustomobject]@{file='test1.png';id='test1';name='Test #1';amount=1} + [pscustomobject]@{file='test2.png';id='test2';name='Test #2';amount=1} +) + +#init +cd C:\Users\user\Documents\cardano\ipfs +$policyId= Get-Content ..\policy\policyid.txt -TotalCount 1 +$data | ConvertTo-Json | Out-File "nft_config.json" + +#create file +"{ + `"721`": { + `"$policyId`": {" | Out-File -FilePath nft_meta.json +for ($i=0; $i -lt $data.length; $i++){ + $hash = $(& $curlExe 'https://ipfs.blockfrost.io/api/v0/ipfs/add', + '-X', 'POST', + '-H', "project_id: $blockfrostApiKey", + '-F', "file=@$($data[$i].file)"| Out-String | ConvertFrom-Json).ipfs_hash +" `"$($data[$i].id)`": { + `"name`": `"$($data[$i].name)`", + `"image`": `"ipfs://$hash`" + }"+(&{if($i -lt $data.length-1) {","} else {""}}) >> nft_meta.json +} +" } + } +}" >> nft_meta.json +[string]::Join( "`n", (gc nft_meta.json)) | sc nft_meta.json \ No newline at end of file diff --git a/mint/mint.ps1 b/mint/mint.ps1 new file mode 100644 index 0000000..6e34419 --- /dev/null +++ b/mint/mint.ps1 @@ -0,0 +1,107 @@ +#params +[bool] $test = 1 +$projectId="test001" +$timeToMint = 3200 # 1 hour + +if($test){ + $network="--testnet-magic", "1097911063" + $addr="addr_test1xxxxxxxxxxxxxxxxxxxxxx" + $logfile="C:\Users\user\AppData\Roaming\Daedalus Testnet\Logs\pub\cardano-wallet.log" +} else { + $network="--mainnet" + $addr="addr1xxxxxxxxxxxxxxxxxxxxxx" + $logfile="C:\Users\user\AppData\Roaming\Daedalus Mainnet\Logs\pub\cardano-wallet.log" +} + +#init +cd C:\Users\user\Documents\cardano + +Select-String '^.*--node-socket (\S+).*$' $logfile | + Select-Object -Last 1 | + ForEach-Object { $socket = $_.Matches[0].Groups[1].Value } #get last occurence in file +$env:CARDANO_NODE_SOCKET_PATH = $socket + +$policyId= Get-Content policy\policyid.txt -TotalCount 1 + +#fetch metadata +$data = Get-Content ipfs\nft_config.json -Raw | ConvertFrom-Json +$mint = "" +for ($i=0; $i -lt $data.length; $i++){ + $mint +="`"$($data[$i].amount) $($policyId).$($data[$i].id)`""+(&{if($i -lt $data.length-1) {"+"} else {""}}) +} + +cd mint + +Write-Host("network : "+$network) +Write-Host("logfile : "+$logfile) +Write-Host("socket : "+$socket) +Write-Host("policyid : "+$policyId) +Write-Host("mint : "+$mint) + +#process +$tip = cardano-cli query tip $network +$slot = ($tip | Out-String | ConvertFrom-Json).slot + +cardano-cli query protocol-parameters $network --out-file protocol.json +$balance = cardano-cli query utxo --address $addr $network +$balance > balance.txt +$balance = $balance[2..($balance.Length-1)] # remove header and separator + +$tx = $balance -replace '^(\S+)\s+(\d+)\s+(\d+) lovelace.*$', '$1#$2' +$amounts = $balance -replace '^(\S+)\s+(\d+)\s+(\d+) lovelace.*$', '$3' +$premint = $balance -replace '^(\S+)\s+(\d+)\s+(\d+) lovelace(( \+ \d+ [a-f0-9]{56}\.\S+)*) \+ TxOutDatumHashNone$', '$4"' +$premint = $premint -replace ' \+ ', '"+"' +$premint = $premint.substring(2) +Write-Host("premint : "+$premint) + +$txin = $tx[0] +$txout = "$($addr)+$($amounts[0])+$($premint)+$($mint)" + +cardano-cli transaction build-raw ` + --fee 0 ` + --tx-in $txin ` + --tx-out $txout ` + --mint=$mint ` + --minting-script-file ../policy/policy.script ` + --metadata-json-file ../ipfs/nft_meta.json ` + --invalid-hereafter=29541804 ` + --out-file matx.raw + +#get fee +$fee = cardano-cli transaction calculate-min-fee ` + --tx-body-file matx.raw ` + --tx-in-count 1 ` + --tx-out-count 1 ` + --witness-count 2 ` + --mainnet ` + --protocol-params-file protocol.json +$fee = $fee -replace '^(\d+) Lovelace$', '$1' + +$txout = "$($addr)+$($amounts[0]-$fee)+$($premint)+$($mint)" + +Write-Host("txin : $($txin)") +Write-Host("txout : $($txout)") +Write-Host("amount : $($amounts[0]) - $($fee) = $($amounts[0]-$fee)") + +#Write-Host($slot+$timeToMint) # 2do before +$before = 41480089 + +cardano-cli transaction build-raw ` + --fee $fee ` + --tx-in $txin ` + --tx-out $txout ` + --mint="$mint" ` + --minting-script-file ../policy/policy.script ` + --metadata-json-file ../ipfs/nft_meta.json ` + --invalid-hereafter=$before ` + --out-file matx.raw + +cardano-cli transaction sign ` + --signing-key-file ../payskey/tn.payment-0.skey ` + --signing-key-file ../payskey/tn.stake.skey ` + --signing-key-file ../policy/policy.skey ` + $network ` + --tx-body-file matx.raw ` + --out-file matx.signed + +cardano-cli transaction submit --tx-file matx.signed $network \ No newline at end of file diff --git a/payskey/1getpayskey.cmd b/payskey/1getpayskey.cmd new file mode 100644 index 0000000..8f9952c --- /dev/null +++ b/payskey/1getpayskey.cmd @@ -0,0 +1,10 @@ +echo average puppy recipe ... party | cardano-address key from-recovery-phrase Shelley > tn.root.prv +cardano-wallet key child 1852H/1815H/0H/1/1 < tn.root.prv > tn.payment-0.prv +cardano-wallet key public --without-chain-code < tn.payment-0.prv > tn.payment-0.pub +cardano-cli key convert-cardano-address-key --shelley-payment-key --signing-key-file tn.payment-0.prv --out-file tn.payment-0.skey +cardano-wallet key child 1852H/1815H/0H/2/0 < tn.root.prv > tn.stake.prv +cardano-wallet key public --without-chain-code < tn.stake.prv > tn.stake.pub +cardano-cli key convert-cardano-address-key --shelley-payment-key --signing-key-file tn.stake.prv --out-file tn.stake.skey +cardano-cli key verification-key --signing-key-file tn.stake.skey --verification-key-file tn.stake.vkey + +pause \ No newline at end of file diff --git a/payskey/2getaddresses.cmd b/payskey/2getaddresses.cmd new file mode 100644 index 0000000..ce785a4 --- /dev/null +++ b/payskey/2getaddresses.cmd @@ -0,0 +1,9 @@ +rem 5. Generate the addresses by computing the payment key and the stake key +cardano-cli address build --testnet-magic 1097911063 --payment-verification-key addr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --stake-verification-key stake_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --out-file tn.payment-0.address +rem ^ tn.payment-0.pub ^ tn.stake.pub +rem If you cat this address tn.payment-0.address it should match your address in your wallet. + +rem Now you can generate your payment using: +rem Source payment address: tn.payment-0.address +rem Source payment signing key: tn.payment-0.skey +pause \ No newline at end of file diff --git a/policy/getpolicy.ps1 b/policy/getpolicy.ps1 new file mode 100644 index 0000000..c100797 --- /dev/null +++ b/policy/getpolicy.ps1 @@ -0,0 +1,49 @@ +#params +[bool] $test = 1 +$timeToMint = 3200 # 1 hour + +if($test){ + $network="--testnet-magic", "1097911063" + $addr="addr_test1xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + $logfile="C:\Users\user\AppData\Roaming\Daedalus Testnet\Logs\pub\cardano-wallet.log" +} else { + $network="--mainnet" + $addr="addr1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + $logfile="C:\Users\user\AppData\Roaming\Daedalus Mainnet\Logs\pub\cardano-wallet.log" +} + +#init +cd C:\Users\user\Documents\cardano + +Select-String '^.*--node-socket (\S+).*$' $logfile | + Select-Object -Last 1 | + ForEach-Object { $socket = $_.Matches[0].Groups[1].Value } #get last occurence in file +$env:CARDANO_NODE_SOCKET_PATH = $socket + +cd policy + +cardano-cli address key-gen --verification-key-file policy.vkey --signing-key-file policy.skey +$hash = cardano-cli address key-hash --payment-verification-key-file policy.vkey + + +"{ + `"type`": `"all`", + `"scripts`": [ + { + `"keyHash`": `"$hash`", + `"type`": `"sig`" + }, + { + `"type`": `"before`", + `"slot`": $before + } + ] +}" | Out-File -FilePath policy.script +[string]::Join( "`n", (gc policy.script)) | sc policy.script + +$tip = cardano-cli query tip $network +$slot = ($tip | Out-String | ConvertFrom-Json).slot +$before = 41480089 +$policyId = cardano-cli transaction policyid --script-file policy.script + +Write-Host($policyId > policyid.txt) \ No newline at end of file