@@ -2584,13 +2584,10 @@ struct RawIssuanceDetails
2584
2584
2585
2585
// Appends a single issuance to the first input that doesn't have one, and includes
2586
2586
// a single output per asset type in shuffled positions.
2587
- void issueasset_base (CMutableTransaction& mtx, RawIssuanceDetails& issuance_details, const CAmount asset_amount, const CAmount token_amount, const std::string& asset_address_str , const std::string& token_address_str , const bool blind_issuance, const uint256& contract_hash)
2587
+ void issueasset_base (CMutableTransaction& mtx, RawIssuanceDetails& issuance_details, const CAmount asset_amount, const CAmount token_amount, const CTxDestination& asset_dest , const CTxDestination& token_dest , const bool blind_issuance, const uint256& contract_hash)
2588
2588
{
2589
-
2590
- CTxDestination asset_address (DecodeDestination (asset_address_str));
2591
- CTxDestination token_address (DecodeDestination (token_address_str));
2592
- CScript asset_destination = GetScriptForDestination (asset_address);
2593
- CScript token_destination = GetScriptForDestination (token_address);
2589
+ CScript asset_script = GetScriptForDestination (asset_dest);
2590
+ CScript token_script = GetScriptForDestination (token_dest);
2594
2591
2595
2592
// Find an input with no issuance field
2596
2593
size_t issuance_input_index = 0 ;
@@ -2624,41 +2621,40 @@ void issueasset_base(CMutableTransaction& mtx, RawIssuanceDetails& issuance_deta
2624
2621
int asset_place = GetRandInt (mtx.vout .size ()-1 );
2625
2622
int token_place = GetRandInt (mtx.vout .size ()); // Don't bias insertion
2626
2623
2627
- CTxOut asset_out (asset, asset_amount, asset_destination);
2628
- // If blinded address, insert the pubkey into the nonce field for later substitution by blinding
2629
- if (IsBlindDestination (asset_address)) {
2630
- CPubKey asset_blind = GetDestinationBlindingKey (asset_address);
2631
- asset_out.nNonce .vchCommitment = std::vector<unsigned char >(asset_blind.begin (), asset_blind.end ());
2624
+ assert (asset_amount > 0 || token_amount > 0 );
2625
+ if (asset_amount > 0 ) {
2626
+ CTxOut asset_out (asset, asset_amount, asset_script);
2627
+ // If blinded address, insert the pubkey into the nonce field for later substitution by blinding
2628
+ if (IsBlindDestination (asset_dest)) {
2629
+ CPubKey asset_blind = GetDestinationBlindingKey (asset_dest);
2630
+ asset_out.nNonce .vchCommitment = std::vector<unsigned char >(asset_blind.begin (), asset_blind.end ());
2631
+ }
2632
+
2633
+ mtx.vout .insert (mtx.vout .begin ()+asset_place, asset_out);
2632
2634
}
2633
2635
// Explicit 0 is represented by a null value, don't set to non-null in that case
2634
2636
if (blind_issuance || asset_amount != 0 ) {
2635
2637
mtx.vin [issuance_input_index].assetIssuance .nAmount = asset_amount;
2636
2638
}
2637
- // Don't make zero value output(impossible by consensus)
2638
- if (asset_amount > 0 ) {
2639
- mtx.vout .insert (mtx.vout .begin ()+asset_place, asset_out);
2640
- }
2641
2639
2642
- CTxOut token_out (token, token_amount, token_destination);
2643
- // If blinded address, insert the pubkey into the nonce field for later substitution by blinding
2644
- if (IsBlindDestination (token_address)) {
2645
- CPubKey token_blind = GetDestinationBlindingKey (token_address);
2646
- token_out.nNonce .vchCommitment = std::vector<unsigned char >(token_blind.begin (), token_blind.end ());
2647
- }
2648
- // Explicit 0 is represented by a null value, don't set to non-null in that case
2649
2640
if (token_amount > 0 ) {
2641
+ CTxOut token_out (token, token_amount, token_script);
2642
+ // If blinded address, insert the pubkey into the nonce field for later substitution by blinding
2643
+ if (IsBlindDestination (token_dest)) {
2644
+ CPubKey token_blind = GetDestinationBlindingKey (token_dest);
2645
+ token_out.nNonce .vchCommitment = std::vector<unsigned char >(token_blind.begin (), token_blind.end ());
2646
+ }
2647
+
2650
2648
mtx.vin [issuance_input_index].assetIssuance .nInflationKeys = token_amount;
2651
2649
mtx.vout .insert (mtx.vout .begin ()+token_place, token_out);
2652
2650
}
2653
2651
}
2654
2652
2655
2653
// Appends a single reissuance to the specified input if none exists,
2656
2654
// and the corresponding output in a shuffled position. Errors otherwise.
2657
- void reissueasset_base (CMutableTransaction& mtx, int & issuance_input_index, const CAmount asset_amount, const std::string& asset_address_str , const uint256& asset_blinder, const uint256& entropy)
2655
+ void reissueasset_base (CMutableTransaction& mtx, int & issuance_input_index, const CAmount asset_amount, const CTxDestination& asset_dest , const uint256& asset_blinder, const uint256& entropy)
2658
2656
{
2659
-
2660
- CTxDestination asset_address (DecodeDestination (asset_address_str));
2661
- CScript asset_destination = GetScriptForDestination (asset_address);
2657
+ CScript asset_script = GetScriptForDestination (asset_dest);
2662
2658
2663
2659
// Check if issuance already exists, error if already exists
2664
2660
if ((size_t )issuance_input_index >= mtx.vin .size () || !mtx.vin [issuance_input_index].assetIssuance .IsNull ()) {
@@ -2677,10 +2673,10 @@ void reissueasset_base(CMutableTransaction& mtx, int& issuance_input_index, cons
2677
2673
assert (mtx.vout .size () >= 1 );
2678
2674
int asset_place = GetRandInt (mtx.vout .size ()-1 );
2679
2675
2680
- CTxOut asset_out (asset, asset_amount, asset_destination );
2676
+ CTxOut asset_out (asset, asset_amount, asset_script );
2681
2677
// If blinded address, insert the pubkey into the nonce field for later substitution by blinding
2682
- if (IsBlindDestination (asset_address )) {
2683
- CPubKey asset_blind = GetDestinationBlindingKey (asset_address );
2678
+ if (IsBlindDestination (asset_dest )) {
2679
+ CPubKey asset_blind = GetDestinationBlindingKey (asset_dest );
2684
2680
asset_out.nNonce .vchCommitment = std::vector<unsigned char >(asset_blind.begin (), asset_blind.end ());
2685
2681
}
2686
2682
assert (asset_amount > 0 );
@@ -2733,9 +2729,6 @@ UniValue rawissueasset(const JSONRPCRequest& request)
2733
2729
2734
2730
UniValue issuances = request.params [1 ].get_array ();
2735
2731
2736
- std::string asset_address_str = " " ;
2737
- std::string token_address_str = " " ;
2738
-
2739
2732
UniValue ret (UniValue::VARR);
2740
2733
2741
2734
// Count issuances, only append hex to final one
@@ -2745,6 +2738,9 @@ UniValue rawissueasset(const JSONRPCRequest& request)
2745
2738
const UniValue& issuance = issuances[idx];
2746
2739
const UniValue& issuance_o = issuance.get_obj ();
2747
2740
2741
+ CTxDestination asset_dest = CNoDestination ();
2742
+ CTxDestination token_dest = CNoDestination ();
2743
+
2748
2744
CAmount asset_amount = 0 ;
2749
2745
const UniValue& asset_amount_uni = issuance_o[" asset_amount" ];
2750
2746
if (asset_amount_uni.isNum ()) {
@@ -2756,7 +2752,10 @@ UniValue rawissueasset(const JSONRPCRequest& request)
2756
2752
if (!asset_address_uni.isStr ()) {
2757
2753
throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, missing corresponding asset_address" );
2758
2754
}
2759
- asset_address_str = asset_address_uni.get_str ();
2755
+ asset_dest = DecodeDestination (asset_address_uni.get_str ());
2756
+ if (boost::get<CNoDestination>(&asset_dest)) {
2757
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Invalid asset address provided: %s" , asset_address_uni.get_str ()));
2758
+ }
2760
2759
}
2761
2760
2762
2761
CAmount token_amount = 0 ;
@@ -2770,8 +2769,12 @@ UniValue rawissueasset(const JSONRPCRequest& request)
2770
2769
if (!token_address_uni.isStr ()) {
2771
2770
throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, missing corresponding token_address" );
2772
2771
}
2773
- token_address_str = token_address_uni.get_str ();
2772
+ token_dest = DecodeDestination (token_address_uni.get_str ());
2773
+ if (boost::get<CNoDestination>(&token_dest)) {
2774
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Invalid token address provided: %s" , token_address_uni.get_str ()));
2775
+ }
2774
2776
}
2777
+
2775
2778
if (asset_amount == 0 && token_amount == 0 ) {
2776
2779
throw JSONRPCError (RPC_TYPE_ERROR, " Issuance must have one non-zero component" );
2777
2780
}
@@ -2788,7 +2791,7 @@ UniValue rawissueasset(const JSONRPCRequest& request)
2788
2791
2789
2792
RawIssuanceDetails details;
2790
2793
2791
- issueasset_base (mtx, details, asset_amount, token_amount, asset_address_str, token_address_str , blind_issuance, contract_hash);
2794
+ issueasset_base (mtx, details, asset_amount, token_amount, asset_dest, token_dest , blind_issuance, contract_hash);
2792
2795
if (details.input_index == -1 ) {
2793
2796
throw JSONRPCError (RPC_INVALID_PARAMETER, " Failed to find enough blank inputs for listed issuances." );
2794
2797
}
@@ -2872,7 +2875,10 @@ UniValue rawreissueasset(const JSONRPCRequest& request)
2872
2875
if (!asset_address_uni.isStr ()) {
2873
2876
throw JSONRPCError (RPC_INVALID_PARAMETER, " Reissuance missing asset_address" );
2874
2877
}
2875
- std::string asset_address_str = asset_address_uni.get_str ();
2878
+ CTxDestination asset_dest = DecodeDestination (asset_address_uni.get_str ());
2879
+ if (boost::get<CNoDestination>(&asset_dest)) {
2880
+ throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" Invalid asset address provided: %s" , asset_address_uni.get_str ()));
2881
+ }
2876
2882
2877
2883
int input_index = -1 ;
2878
2884
const UniValue& input_index_o = issuance_o[" input_index" ];
@@ -2889,7 +2895,7 @@ UniValue rawreissueasset(const JSONRPCRequest& request)
2889
2895
2890
2896
uint256 entropy = ParseHashV (issuance_o[" entropy" ], " entropy" );
2891
2897
2892
- reissueasset_base (mtx, input_index, asset_amount, asset_address_str , asset_blinder, entropy);
2898
+ reissueasset_base (mtx, input_index, asset_amount, asset_dest , asset_blinder, entropy);
2893
2899
if (input_index == -1 ) {
2894
2900
throw JSONRPCError (RPC_INVALID_PARAMETER, " Selected transaction input already has issuance data." );
2895
2901
}
0 commit comments