Skip to content

Commit

Permalink
init dump
Browse files Browse the repository at this point in the history
  • Loading branch information
njank committed Sep 12, 2021
1 parent 2b9c2bd commit 6790197
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ipfs/ipfs.ps1
Original file line number Diff line number Diff line change
@@ -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
107 changes: 107 additions & 0 deletions mint/mint.ps1
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions payskey/1getpayskey.cmd
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions payskey/2getaddresses.cmd
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions policy/getpolicy.ps1
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6790197

Please sign in to comment.