Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
issue asset to many addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
nmushegian committed Jan 30, 2015
1 parent b71caf9 commit bfabbd6
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 6 deletions.
21 changes: 20 additions & 1 deletion libraries/api/wallet_api.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion libraries/blockchain/include/bts/blockchain/config.hpp
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions libraries/client/wallet_api.cpp
Expand Up @@ -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<string, share_type>& addresses )
{
auto record = _wallet->issue_asset_to_addresses( symbol, addresses );
_wallet->cache_transaction( record );
network_broadcast_transaction( record.trx );
return record;
}


vector<string> detail::client_impl::wallet_list() const
{
return _wallet->list();
Expand Down
4 changes: 4 additions & 0 deletions libraries/wallet/include/bts/wallet/wallet.hpp
Expand Up @@ -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<string, share_type>& addresses );

/**
* ie: submit_bid( 10 BTC at 600.34 USD per BTC )
*
Expand Down
64 changes: 64 additions & 0 deletions libraries/wallet/wallet.cpp
Expand Up @@ -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<string, share_type>& addresses )
{ try {
FC_ASSERT( is_open() );
FC_ASSERT( is_unlocked() );
FC_ASSERT( my->_blockchain->is_valid_symbol( symbol ) );

signed_transaction trx;
unordered_set<address> 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 )
{
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance_tests/features/advanced_uia.feature
Expand Up @@ -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
Expand All @@ -35,19 +35,19 @@ 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]

This comment has been minimized.

Copy link
@robrigo

robrigo Feb 1, 2015

Contributor

spotted a typo here

restircted -> restricted

This comment has been minimized.

Copy link
@vikramrajkumar

vikramrajkumar Feb 1, 2015

Contributor
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
And I set asset state for ALICE to: [market_halt]
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.
Expand Down

0 comments on commit bfabbd6

Please sign in to comment.