Skip to content

Commit

Permalink
Add receiver field to escrow release operation steemit#143
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Sep 11, 2016
1 parent 78e39fa commit 0c84d97
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,10 @@ namespace steemit { namespace chain {
struct escrow_release_operation : public base_operation
{
string from;
string to; ///< the account that should receive funds (might be from, might be to
string to; ///< the original 'to'
string agent;
string who; ///< the account that is attempting to release the funds, determines valid 'to'
string who; ///< the account that is attempting to release the funds, determines valid 'receiver'
string receiver; ///< the account that should receive funds (might be from, might be to)
uint32_t escrow_id = 0;
asset sbd_amount = asset( 0, SBD_SYMBOL ); ///< the amount of sbd to release
asset steem_amount = asset( 0, STEEM_SYMBOL ); ///< the amount of steem to release
Expand Down Expand Up @@ -976,7 +977,7 @@ FC_REFLECT( steemit::chain::comment_options_operation, (author)(permlink)(max_ac
FC_REFLECT( steemit::chain::escrow_transfer_operation, (from)(to)(sbd_amount)(steem_amount)(escrow_id)(agent)(fee)(json_meta)(ratification_deadline)(escrow_expiration) );
FC_REFLECT( steemit::chain::escrow_approve_operation, (from)(to)(agent)(who)(escrow_id)(approve) );
FC_REFLECT( steemit::chain::escrow_dispute_operation, (from)(to)(agent)(who)(escrow_id) );
FC_REFLECT( steemit::chain::escrow_release_operation, (from)(to)(agent)(who)(escrow_id)(sbd_amount)(steem_amount) );
FC_REFLECT( steemit::chain::escrow_release_operation, (from)(to)(agent)(who)(receiver)(escrow_id)(sbd_amount)(steem_amount) );
FC_REFLECT( steemit::chain::challenge_authority_operation, (challenger)(challenged)(require_owner) );
FC_REFLECT( steemit::chain::prove_authority_operation, (challenged)(require_owner) );
FC_REFLECT( steemit::chain::request_account_recovery_operation, (recovery_account)(account_to_recover)(new_owner_authority)(extensions) );
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ namespace steemit { namespace chain {
validate_account_name( to );
validate_account_name( agent );
validate_account_name( who );
validate_account_name( receiver );
FC_ASSERT( who == from || who == to || who == agent, "who must be from or to or agent" );
FC_ASSERT( receiver == from || receiver == to, "receiver must be from or to" );
FC_ASSERT( sbd_amount.amount >= 0, "sbd amount cannot be negative" );
FC_ASSERT( steem_amount.amount >= 0, "steem amount cannot be negative" );
FC_ASSERT( sbd_amount.amount > 0 || steem_amount.amount > 0, "escrow must release a non-zero amount" );
Expand Down
14 changes: 7 additions & 7 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,14 @@ void escrow_release_evaluator::do_apply( const escrow_release_operation& o )
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_14__143 ), "op is not valid until next hardfork" ); /// TODO: remove this after HF14

const auto& from_account = db().get_account(o.from);
const auto& to_account = db().get_account(o.to);
const auto& who_account = db().get_account(o.who);
const auto& receiver_account = db().get_account(o.receiver);

const auto& e = db().get_escrow( o.from, o.escrow_id );
FC_ASSERT( e.steem_balance >= o.steem_amount, "Release amount exceeds escrow balance" );
FC_ASSERT( e.sbd_balance >= o.sbd_amount, "Release amount exceeds escrow balance" );
FC_ASSERT( o.to == e.from || o.to == e.to, "Funds must be released to 'from' or 'to'" );
FC_ASSERT( e.to == o.to, "op 'to' does not match escrow 'to'");
FC_ASSERT( e.agent == o.agent, "op 'agent' does not match escrow 'agent'" );
FC_ASSERT( o.receiver == e.from || o.receiver == e.to, "Funds must be released to 'from' or 'to'" );
FC_ASSERT( e.to_approved && e.agent_approved, "Funds cannot be released prior to escrow approval" );

// If there is a dispute regardless of expiration, the agent can release funds to either party
Expand All @@ -622,18 +622,18 @@ void escrow_release_evaluator::do_apply( const escrow_release_operation& o )
// If there is no dispute and escrow has not expired, either party can release funds to the other.
if( o.who == e.from )
{
FC_ASSERT( o.to == e.to, "'from' must release funds to 'to'" );
FC_ASSERT( o.receiver == e.to, "'from' must release funds to 'to'" );
}
else if( o.who == e.to )
{
FC_ASSERT( o.to == e.from, "'to' must release funds to 'from'" );
FC_ASSERT( o.receiver == e.from, "'to' must release funds to 'from'" );
}
}
}
// If escrow expires and there is no dispute, either party can release funds to either party.

db().adjust_balance( to_account, o.steem_amount );
db().adjust_balance( to_account, o.sbd_amount );
db().adjust_balance( receiver_account, o.steem_amount );
db().adjust_balance( receiver_account, o.sbd_amount );

db().modify( e, [&]( escrow_object& esc )
{
Expand Down
4 changes: 3 additions & 1 deletion libraries/wallet/include/steemit/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,10 @@ class wallet_api
* Release funds help in escrow
*
* @param from The account that funded the escrow
* @param to The account that will receive funds being released
* @param to The account the funds are originally going to
* @param agent The account acting as the agent in case of dispute
* @param who The account authorizing the release
* @param receiver The account that will receive funds being released
* @param escrow_id A unique id for the escrow transfer
* @param sbd_amount The amount of SBD that will be released
* @param steem_amount The amount of STEEM that will be released
Expand All @@ -655,6 +656,7 @@ class wallet_api
string to,
string agent,
string who,
string receiver,
uint32_t escrow_id,
asset sbd_amount,
asset steem_amount,
Expand Down
2 changes: 2 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,7 @@ annotated_signed_transaction wallet_api::escrow_release(
string to,
string agent,
string who,
string receiver,
uint32_t escrow_id,
asset sbd_amount,
asset steem_amount,
Expand All @@ -1854,6 +1855,7 @@ annotated_signed_transaction wallet_api::escrow_release(
op.to = to;
op.agent = agent;
op.who = who;
op.receiver = receiver;
op.escrow_id = escrow_id;
op.sbd_amount = sbd_amount;
op.steem_amount = steem_amount;
Expand Down

0 comments on commit 0c84d97

Please sign in to comment.