From bfabbd6919878b87a3e7adb8f0af8dfcb4d05206 Mon Sep 17 00:00:00 2001 From: Nikolai Mushegian Date: Fri, 30 Jan 2015 16:05:15 -0500 Subject: [PATCH] issue asset to many addresses --- libraries/api/wallet_api.json | 21 +++++- .../include/bts/blockchain/config.hpp | 2 +- libraries/client/wallet_api.cpp | 11 ++++ .../wallet/include/bts/wallet/wallet.hpp | 4 ++ libraries/wallet/wallet.cpp | 64 +++++++++++++++++++ .../features/advanced_uia.feature | 8 +-- 6 files changed, 104 insertions(+), 6 deletions(-) diff --git a/libraries/api/wallet_api.json b/libraries/api/wallet_api.json index d5498ad9d..f7a987563 100644 --- a/libraries/api/wallet_api.json +++ b/libraries/api/wallet_api.json @@ -1760,7 +1760,7 @@ "name" : "issuer_permissions", "type" : "asset_permission_array", "description" : "a set of permissions an issuer retains", - "default_value" : ["retractable","market_halt","balance_halt","supply_limit"] + "default_value" : ["restricted", "retractable","market_halt","balance_halt","supply_limit"] }, { "name" : "issuer_account_name", @@ -1813,6 +1813,25 @@ "detailed_description" : "The asset being issued must have been created via wallet_asset_create in a previous block.", "prerequisites" : ["wallet_unlocked"] }, + { + "method_name" : "wallet_asset_issue_to_addresses", + "description" : "Issues new UIA shares to specific addresses.", + "return_type" : "transaction_record", + "parameters" : [ + { + "name" : "symbol", + "type" : "asset_symbol", + "description" : "the ticker symbol for asset" + }, + { + "name" : "addresses", + "type" : "snapshot_map", + "description" : "A map of addresses-to-amounts to transfer the new shares to", + } + ], + "detailed_description" : "This is intended to be used with a helper script to break up snapshots. It will not do any magic for you.", + "prerequisites" : ["wallet_unlocked"] + }, { "method_name" : "wallet_escrow_summary", "description" : "Lists the total asset balances for all open escrows", diff --git a/libraries/blockchain/include/bts/blockchain/config.hpp b/libraries/blockchain/include/bts/blockchain/config.hpp index 4e1f9ebfc..9b8394e2d 100644 --- a/libraries/blockchain/include/bts/blockchain/config.hpp +++ b/libraries/blockchain/include/bts/blockchain/config.hpp @@ -62,7 +62,7 @@ #define BTS_BLOCKCHAIN_MIN_BURN_FEE BTS_BLOCKCHAIN_PRECISION * 1 // 1 XTS #ifdef BTS_TEST_NETWORK -#define BTS_BLOCKCHAIN_VOTE_UPDATE_PERIOD_SEC 40 +#define BTS_BLOCKCHAIN_VOTE_UPDATE_PERIOD_SEC 10 #else #define BTS_BLOCKCHAIN_VOTE_UPDATE_PERIOD_SEC (60*60) // 1 hour #endif diff --git a/libraries/client/wallet_api.cpp b/libraries/client/wallet_api.cpp index d55c1d2f2..699aec3b8 100644 --- a/libraries/client/wallet_api.cpp +++ b/libraries/client/wallet_api.cpp @@ -903,6 +903,17 @@ wallet_transaction_record detail::client_impl::wallet_asset_issue( return record; } +wallet_transaction_record detail::client_impl::wallet_asset_issue_to_addresses( + const string& symbol, + const map& addresses ) +{ + auto record = _wallet->issue_asset_to_addresses( symbol, addresses ); + _wallet->cache_transaction( record ); + network_broadcast_transaction( record.trx ); + return record; +} + + vector detail::client_impl::wallet_list() const { return _wallet->list(); diff --git a/libraries/wallet/include/bts/wallet/wallet.hpp b/libraries/wallet/include/bts/wallet/wallet.hpp index 72cef28ec..f8fe1ec64 100644 --- a/libraries/wallet/include/bts/wallet/wallet.hpp +++ b/libraries/wallet/include/bts/wallet/wallet.hpp @@ -462,6 +462,10 @@ namespace bts { namespace wallet { const string& memo_message, bool sign ); + wallet_transaction_record issue_asset_to_addresses( + const string& symbol, + const map& addresses ); + /** * ie: submit_bid( 10 BTC at 600.34 USD per BTC ) * diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index dc4e40a4e..a5be6a751 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3400,6 +3400,70 @@ namespace detail { return record; } FC_CAPTURE_AND_RETHROW() } + + wallet_transaction_record wallet::issue_asset_to_addresses( + const string& symbol, + const map& addresses ) + { try { + FC_ASSERT( is_open() ); + FC_ASSERT( is_unlocked() ); + FC_ASSERT( my->_blockchain->is_valid_symbol( symbol ) ); + + signed_transaction trx; + unordered_set
required_signatures; + + trx.expiration = blockchain::now() + get_transaction_expiration(); + + auto required_fees = get_transaction_fee(); + + auto asset_record = my->_blockchain->get_asset_record( symbol ); + FC_ASSERT(asset_record.valid(), "no such asset record"); + auto issuer_account = my->_blockchain->get_account_record( asset_record->issuer_account_id ); + FC_ASSERT(issuer_account, "uh oh! no account for valid asset"); + auto authority = asset_record->authority; + + asset shares_to_issue( 0, asset_record->id ); + + for( auto pair : addresses ) + { + auto addr = address( pair.first ); + auto amount = asset( pair.second, asset_record->id ); + trx.deposit( addr, amount ); + shares_to_issue += amount; + } + my->withdraw_to_transaction( required_fees, + issuer_account->name, + trx, + required_signatures ); + trx.issue( shares_to_issue ); + for( auto owner : authority.owners ) + required_signatures.insert( owner ); +// required_signatures.insert( issuer_account->active_key() ); + + owallet_account_record issuer = my->_wallet_db.lookup_account( asset_record->issuer_account_id ); + FC_ASSERT( issuer.valid() ); + owallet_key_record issuer_key = my->_wallet_db.lookup_key( issuer->owner_address() ); + FC_ASSERT( issuer_key && issuer_key->has_private_key() ); + + auto entry = ledger_entry(); + entry.from_account = issuer->active_key(); + entry.amount = shares_to_issue; + entry.memo = "issue to many addresses"; + + auto record = wallet_transaction_record(); + record.ledger_entries.push_back( entry ); + record.fee = required_fees; + + // if( sign ) + my->sign_transaction( trx, required_signatures ); + + record.trx = trx; + return record; + } FC_CAPTURE_AND_RETHROW() } + + + + void wallet::update_account_private_data( const string& account_to_update, const variant& private_data ) { diff --git a/tests/acceptance_tests/features/advanced_uia.feature b/tests/acceptance_tests/features/advanced_uia.feature index 2f6fff67f..ed77821c0 100644 --- a/tests/acceptance_tests/features/advanced_uia.feature +++ b/tests/acceptance_tests/features/advanced_uia.feature @@ -26,7 +26,7 @@ Feature: Advanced User Issued Asset Functionality | ALICE | alice_iou | 100000 | 1000000000 | 1000 | Scenario: Alice removes the "supply_unlimit" permission and can't change it back When I'm Alice - And I set asset permissions for ALICE to: [retractable, market_halt, balance_halt] + And I set asset permissions for ALICE to: [restricted, retractable, market_halt, balance_halt] And I wait for one block # And I issue 100 ALICE to account: alice TODO assert fail # And I wait for one block @@ -35,10 +35,12 @@ Feature: Advanced User Issued Asset Functionality # | ALICE | alice_iou | 100000 | 1000000000 | 1000 | #TODO this should fail!! - And I set asset permissions for ALICE to: [retractable, market_halt, balance_halt, supply_unlimit] + And I set asset permissions for ALICE to: [restircted, retractable, market_halt, balance_halt, supply_unlimit] And I wait for one block Scenario: Customer can send his asset to anyone and anybody can trade in the ALICE market. + Scenario: Alice can make the asset restricted and whitelist only customer, meaning Bob can't receive or trade in ALICE markets + Scenario: Alice can freeze the market, meaning not even bob can trade. When I'm Bob And I submit ask for 10 XTS at 1 ALICE/XTS When I'm Alice @@ -46,8 +48,6 @@ Feature: Advanced User Issued Asset Functionality And I wait for one block When I'm Bob # And I submit ask for 10 XTS at 1 ALICE/XTS TODO this should fail - Scenario: Alice can make the asset restricted and whitelist only customer, meaning Bob can't receive or trade in ALICE markets - Scenario: Alice can freeze the market, meaning not even bob can trade. Scenario: Alice can unfreeze the market. Scenario: Alice can spend Bob's funds. Scenario: Alice can unfreeze funds and bob can spend them again.