Skip to content

Commit

Permalink
Update escrow operations for multi-sig use. Does not build #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Aug 15, 2016
1 parent bf15b77 commit 4cadd3d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 26 deletions.
48 changes: 38 additions & 10 deletions libraries/chain/include/steemit/chain/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,15 @@ namespace steemit { namespace chain {
/**
* The purpose of this operation is to enable someone to send money contingently to
* another individual. The funds leave the *from* account and go into a temporary balance
* where they are held until *from* releases it to *to* or *to* refunds it to *from*.
* where they are held until *from* releases it to *to* or *to* refunds it to *from*.
*
* In the event of a dispute the *agent* can divide the funds between the to/from account.
*
* The escrow agent is paid the fee no matter what. It is up to the escrow agent to determine
* This operation only creates a proposed escrow transfer. Both the *agent* and *to* must
* agree to the terms of the arrangement by approving the escrow.
*
* The escrow agent is paid the fee on approval of all parties. It is up to the escrow agent
* to determine the fee.
*
* Escrow transactions are uniquely identified by 'from' and 'escrow_id', the 'escrow_id' is defined
* by the sender.
Expand All @@ -245,19 +249,37 @@ namespace steemit { namespace chain {
{
string from;
string to;
asset amount;
string memo;
asset sbd_amount = asset( 0, SBD_SYMBOL );
asset steem_amount = asset( 0, STEEM_SYMBOL );

uint32_t escrow_id;
uint32_t escrow_id = 0;
string agent;
asset fee;
string json_meta;
time_point_sec expiration;
time_point_sec ratification_expiration;
time_point_sec escrow_expiration;

void validate()const;
void get_required_active_authorities( flat_set<string>& a )const{ a.insert(from); }
};

/**
* The agent and to accounts must approve an escrow transaction for it to be valid on
* the blockchain.
*/
struct escrow_approve_operation : public base_operation
{
string from;
string to;
string agent;
string who; // Either to or agent
uint32_t escrow_id;
bool approve;

void validate()const;
void get_required_active_authorities( flat_set<string>& a )const{ a.insert(who); }
};

/**
* If either the sender or receiver of an escrow payment has an issue, they can
* raise it for dispute. Once a payment is in dispute, the agent has authority over
Expand All @@ -277,14 +299,20 @@ namespace steemit { namespace chain {
/**
* This operation can be used by anyone associated with the escrow transfer to
* release funds if they have permission.
*
* If the escrow transfer expires before approval, only *from* can release funds.
* In this event, *sbd_amount* and *steem_amount* will release from the pending fee
* that was to be paid to the agent.
*/
struct escrow_release_operation : public base_operation
{
string from;
uint32_t escrow_id;
string to; ///< the account that should receive funds (might be from, might be to
string agent; ///< the account that is acting as the escrow agent
string who; ///< the account that is attempting to release the funds, determines valid 'to'
asset amount; ///< the amount of funds to release
asset sbd_amount; ///< the amount of sbd to release
asset steem_amount; ///< the amount of steem to release

void validate()const;
void get_required_active_authorities( flat_set<string>& a )const{ a.insert(who); }
Expand All @@ -303,7 +331,6 @@ namespace steemit { namespace chain {
string to; ///< if null, then same as from
asset amount; ///< must be STEEM


void validate()const;
void get_required_active_authorities( flat_set<string>& a )const{ a.insert(from); }
};
Expand Down Expand Up @@ -843,9 +870,10 @@ FC_REFLECT( steemit::chain::fill_vesting_withdraw_operation, (from_account)(to_a
FC_REFLECT( steemit::chain::delete_comment_operation, (author)(permlink) );
FC_REFLECT( steemit::chain::comment_options_operation, (author)(permlink)(max_accepted_payout)(percent_steem_dollars)(allow_votes)(allow_curation_rewards)(extensions) )

FC_REFLECT( steemit::chain::escrow_transfer_operation, (from)(to)(amount)(memo)(escrow_id)(agent)(fee)(json_meta)(expiration) );
FC_REFLECT( steemit::chain::escrow_transfer_operation, (from)(to)(sbd_amount)(steem_amount)(escrow_id)(agent)(fee)(json_meta)(ratification_expiration)(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)(escrow_id)(who) );
FC_REFLECT( steemit::chain::escrow_release_operation, (from)(to)(escrow_id)(who)(amount) );
FC_REFLECT( steemit::chain::escrow_release_operation, (from)(to)(agent)(escrow_id)(who)(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
24 changes: 16 additions & 8 deletions libraries/chain/include/steemit/chain/steem_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ namespace steemit { namespace chain {
string from;
string to;
string agent;
time_point_sec expiration;
asset balance;
time_point_sec ratification_expiration;
time_point_sec escrow_expiration;
asset sbd_balance;
asset steem_balance;
asset pending_fee;
bool to_approved = false;
bool agent_approved = false;
bool disputed = false;
};

Expand Down Expand Up @@ -67,11 +72,11 @@ namespace steemit { namespace chain {
uint128_t weight = 0;

/// this is the sort index
uint128_t volume_weight()const {
return steem_volume * sbd_volume * is_positive();
uint128_t volume_weight()const {
return steem_volume * sbd_volume * is_positive();
}
uint128_t min_volume_weight()const {
return std::min(steem_volume,sbd_volume) * is_positive();
uint128_t min_volume_weight()const {
return std::min(steem_volume,sbd_volume) * is_positive();
}
void update_weight( bool hf9 ) {
weight = hf9 ? min_volume_weight() : volume_weight();
Expand Down Expand Up @@ -277,5 +282,8 @@ FC_REFLECT_DERIVED( steemit::chain::liquidity_reward_balance_object, (graphene::
FC_REFLECT_DERIVED( steemit::chain::withdraw_vesting_route_object, (graphene::db::object),
(from_account)(to_account)(percent)(auto_vest) )

FC_REFLECT_DERIVED( steemit::chain::escrow_object, (graphene::db::object),
(escrow_id)(from)(to)(agent)(expiration)(balance)(disputed) );
FC_REFLECT_DERIVED( steemit::chain::escrow_object, (graphene::db::object),
(escrow_id)(from)(to)(agent)
(ratification_expiration)(escrow_expiration)
(sbd_balance)(steem_balance)(pending_fee)
(to_approved)(agent_approved)(disputed) );
32 changes: 25 additions & 7 deletions libraries/chain/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,24 @@ namespace steemit { namespace chain {
FC_ASSERT( is_valid_account_name( from ) );
FC_ASSERT( is_valid_account_name( to ) );
FC_ASSERT( is_valid_account_name( agent ) );
FC_ASSERT( fee.amount >= 0 );
FC_ASSERT( amount.amount >= 0 );
FC_ASSERT( from != agent && to != agent );
FC_ASSERT( fee.symbol == amount.symbol );
FC_ASSERT( amount.symbol != VESTS_SYMBOL );
FC_ASSERT( fee.amount >= 0, "fee cannot be negative" );
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 transfer a non-zero amount" );
FC_ASSERT( from != agent && to != agent, "agent must be a third party" );
FC_ASSERT( fee.symbol != VESTS_SYMBOL, "fee cannot be paid in VESTS" );
FC_ASSERT( sbd_amount.symbol == VESTS_SYMBOL, "sbd amount must contain SBD" );
FC_ASSERT( steem_amount.symbol == STEEM_SYMBOL, "steem amount must contain STEEM" );
}

void escrow_approve_operation::validate()const
{
FC_ASSERT( is_valid_account_name( from ) );
FC_ASSERT( is_valid_account_name( to ) );
FC_ASSERT( is_valid_account_name( agent) );
FC_ASSERT( is_valid_account_name( who ) );
FC_ASSERT( from != who, "from account implicitly approved escrow" );
FC_ASSERT( who == to || who == agent, "to or agent must approve escrow" );
}

void escrow_dispute_operation::validate()const
Expand All @@ -308,9 +321,14 @@ namespace steemit { namespace chain {
{
FC_ASSERT( is_valid_account_name( from ) );
FC_ASSERT( is_valid_account_name( to ) );
FC_ASSERT( is_valid_account_name( agent ) );
FC_ASSERT( is_valid_account_name( who ) );
FC_ASSERT( amount.amount > 0 );
FC_ASSERT( amount.symbol != VESTS_SYMBOL );
FC_ASSERT( who == from || who == to || who == agent );
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" );
FC_ASSERT( sbd_amount.symbol == VESTS_SYMBOL, "sbd amount must contain SBD" );
FC_ASSERT( steem_amount.symbol == STEEM_SYMBOL, "steem amount must contain STEEM" );
}

void request_account_recovery_operation::validate()const
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ void escrow_release_evaluator::do_apply( const escrow_release_operation& o )

const auto& e = db().get_escrow( o.from, o.escrow_id );
FC_ASSERT( e.balance >= o.amount && e.balance.symbol == o.amount.symbol );
/// TODO assert o.amount > 0

if( e.expiration > db().head_block_time() )
{
Expand Down

0 comments on commit 4cadd3d

Please sign in to comment.