Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] issueasset contract_hash arg, default of generated key in wallet #560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5713,21 +5713,23 @@ UniValue issueasset(const JSONRPCRequest& request)
return NullUniValue;
}

if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
if (request.fHelp || request.params.size() < 2 || request.params.size() > 4)
throw std::runtime_error(
"issueasset assetamount tokenamount ( blind )\n"
"\nCreate an asset. Must have funds in wallet to do so. Returns asset hex id.\n"
"\nArguments:\n"
"1. \"assetamount\" (numeric or string, required) Amount of asset to generate.\n"
"2. \"tokenamount\" (numeric or string, required) Amount of reissuance tokens to generate. These will allow you to reissue the asset if in wallet using `reissueasset`. These tokens are not consumed during reissuance.\n"
"3. \"blind\" (bool, optional, default=true) Whether to blind the issuances.\n"
"4. \"contract_hash\" (string, optional) 32-byte string to have asset id commit to.\n"
"\nResult:\n"
"{ (json object)\n"
" \"txid\":\"<txid>\", (string) Transaction id for issuance.\n"
" \"vin\":\"n\", (numeric) The input position of the issuance in the transaction.\n"
" \"entropy\":\"<entropy>\", (string) Entropy of the asset type.\n"
" \"asset\":\"<asset>\", (string) Asset type for issuance.\n"
" \"token\":\"<token>\", (string) Token type for issuance.\n"
" \"contract_hash\":<hex> (string) If no `contract_hash` was given as an argument, this will be the SHA256 image of a newly generated public key from your wallet. Can be used to prove authorship of issuance after the fact.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("issueasset", "10 0")
Expand Down Expand Up @@ -5771,17 +5773,26 @@ UniValue issueasset(const JSONRPCRequest& request)
token_dest_blindpub = pwallet->GetBlindingPubKey(GetScriptForDestination(token_dest));
}

uint256 dummyentropy;
CAsset dummyasset;
IssuanceDetails issuance_details;

if (!request.params[3].isNull()) {
issuance_details.contract_hash = ParseHashV(request.params[3], "contract_hash");
} else {
// Finally get contract hash key
if (!pwallet->GetKeyFromPool(newKey)) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
}
issuance_details.contract_hash = newKey.GetHash();
}

issuance_details.blind_issuance = blind_issuances;
CTransactionRef tx_ref = SendGenerationTransaction(GetScriptForDestination(asset_dest), asset_dest_blindpub, GetScriptForDestination(token_dest), token_dest_blindpub, nAmount, nTokens, &issuance_details, pwallet);

// Calculate asset type, assumes first vin is used for issuance
CAsset asset;
CAsset token;
assert(!tx_ref->vin.empty());
GenerateAssetEntropy(issuance_details.entropy, tx_ref->vin[0].prevout, uint256());
GenerateAssetEntropy(issuance_details.entropy, tx_ref->vin[0].prevout, issuance_details.contract_hash);
CalculateAsset(asset, issuance_details.entropy);
CalculateReissuanceToken(token, issuance_details.entropy, blind_issuances);

Expand All @@ -5791,6 +5802,7 @@ UniValue issueasset(const JSONRPCRequest& request)
ret.pushKV("entropy", issuance_details.entropy.GetHex());
ret.pushKV("asset", asset.GetHex());
ret.pushKV("token", token.GetHex());
ret.pushKV("contract_hash", issuance_details.contract_hash.GetHex());
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3223,7 +3223,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
CAsset token;
//TODO take optional contract hash
// Initial issuance always uses vin[0]
GenerateAssetEntropy(entropy, txNew.vin[0].prevout, uint256());
GenerateAssetEntropy(entropy, txNew.vin[0].prevout, issuance_details->contract_hash);
CalculateAsset(asset, entropy);
CalculateReissuanceToken(token, entropy, issuance_details->blind_issuance);
CScript blindingScript(CScript() << OP_RETURN << std::vector<unsigned char>(txNew.vin[0].prevout.hash.begin(), txNew.vin[0].prevout.hash.end()) << txNew.vin[0].prevout.n);
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ struct CoinSelectionParams

struct IssuanceDetails {
bool issuing = false;
uint256 contract_hash;

bool blind_issuance = true;
CAsset reissuance_asset;
Expand Down