Skip to content

Commit

Permalink
Merge pull request steemit#370 from abitmore/escrow-improve2
Browse files Browse the repository at this point in the history
Escrow improvement
  • Loading branch information
bytemaster authored Sep 11, 2016
2 parents bd1ed8b + 0c84d97 commit 07c5e85
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions libraries/app/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,14 @@ struct get_impacted_account_visitor
{
_impacted.insert( op.from );
_impacted.insert( op.to );
_impacted.insert( op.agent );
}

void operator()( const escrow_release_operation& op )
{
_impacted.insert( op.from );
_impacted.insert( op.to );
_impacted.insert( op.agent );
}

//void operator()( const operation& op ){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ namespace steemit { namespace chain {
{
string from;
string to;
string agent;
string who;
uint32_t escrow_id = 0;

Expand All @@ -311,8 +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 who; ///< the account that is attempting to release the funds, determines valid 'to'
string to; ///< the original 'to'
string agent;
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 @@ -973,8 +976,8 @@ 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)(who)(escrow_id) );
FC_REFLECT( steemit::chain::escrow_release_operation, (from)(to)(who)(escrow_id)(sbd_amount)(steem_amount) );
FC_REFLECT( steemit::chain::escrow_dispute_operation, (from)(to)(agent)(who)(escrow_id) );
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
7 changes: 6 additions & 1 deletion libraries/chain/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ namespace steemit { namespace chain {
{
validate_account_name( from );
validate_account_name( to );
FC_ASSERT( is_valid_account_name( agent) );
validate_account_name( agent );
validate_account_name( who );
FC_ASSERT( who == to || who == agent, "to or agent must approve escrow" );
}
Expand All @@ -328,6 +328,7 @@ namespace steemit { namespace chain {
{
validate_account_name( from );
validate_account_name( to );
validate_account_name( agent );
validate_account_name( who );
FC_ASSERT( who == from || who == to, "who must be from or to" );
}
Expand All @@ -336,7 +337,11 @@ namespace steemit { namespace chain {
{
validate_account_name( from );
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
17 changes: 10 additions & 7 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ void escrow_approve_evaluator::do_apply( const escrow_approve_operation& o )

FC_ASSERT( escrow.to == o.to, "op 'to' does not match escrow 'to'" );
FC_ASSERT( escrow.agent == o.agent, "op 'agent' does not match escrow 'agent'" );
FC_ASSERT( escrow.ratification_deadline >= db().head_block_time(), "escrow ratification deadline is before head block time" );

bool reject_escrow = !o.approve;

Expand Down Expand Up @@ -580,6 +581,7 @@ void escrow_dispute_evaluator::do_apply( const escrow_dispute_operation& o )
FC_ASSERT( e.to_approved && e.agent_approved, "escrow must be approved by all parties before a dispute can be raised" );
FC_ASSERT( !e.disputed, "escrow is already under dispute" );
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'" );

db().modify( e, [&]( escrow_object& esc )
{
Expand All @@ -596,13 +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 @@ -619,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
8 changes: 7 additions & 1 deletion libraries/wallet/include/steemit/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,15 @@ class wallet_api
*
* @param from The account that funded the escrow
* @param to The destination of the escrow
* @param agent The account acting as the agent in case of dispute
* @param who The account raising the dispute (either 'from' or 'to')
* @param escrow_id A unique id for the escrow transfer
* @param broadcast true if you wish to broadcast the transaction
*/
annotated_signed_transaction escrow_dispute(
string from,
string to,
string agent,
string who,
uint32_t escrow_id,
bool broadcast = false
Expand All @@ -640,8 +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 @@ -650,7 +654,9 @@ class wallet_api
annotated_signed_transaction escrow_release(
string from,
string to,
string agent,
string who,
string receiver,
uint32_t escrow_id,
asset sbd_amount,
asset steem_amount,
Expand Down
6 changes: 6 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ annotated_signed_transaction wallet_api::escrow_approve(
annotated_signed_transaction wallet_api::escrow_dispute(
string from,
string to,
string agent,
string who,
uint32_t escrow_id,
bool broadcast
Expand All @@ -1772,6 +1773,7 @@ annotated_signed_transaction wallet_api::escrow_dispute(
escrow_dispute_operation op;
op.from = from;
op.to = to;
op.agent = agent;
op.who = who;
op.escrow_id = escrow_id;

Expand Down Expand Up @@ -1839,7 +1841,9 @@ annotated_signed_transaction wallet_api::cancel_transfer_from_savings( string fr
annotated_signed_transaction wallet_api::escrow_release(
string from,
string to,
string agent,
string who,
string receiver,
uint32_t escrow_id,
asset sbd_amount,
asset steem_amount,
Expand All @@ -1849,7 +1853,9 @@ annotated_signed_transaction wallet_api::escrow_release(
escrow_release_operation op;
op.from = from;
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 07c5e85

Please sign in to comment.