Skip to content

Commit

Permalink
Update escrow for hf14 and fix formatting #143
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Aug 15, 2016
1 parent fa2ff2c commit bf15b77
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 61 deletions.
1 change: 1 addition & 0 deletions libraries/chain/hardfork.d/0_14.hf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef STEEMIT_HARDFORK_0_14
#define STEEMIT_HARDFORK_0_14 14
#define STEEMIT_HARDFORK_0_14__143 (STEEMIT_HARDFORK_0_14)

#define STEEMIT_HARDFORK_0_14_TIME 2471269600 // Far future...
#define STEEMIT_HARDFORK_0_14_VERSION hardfork_version( 0, 14 )
Expand Down
148 changes: 87 additions & 61 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,82 +460,108 @@ void comment_evaluator::do_apply( const comment_operation& o )

} FC_CAPTURE_AND_RETHROW( (o) ) }

void escrow_transfer_evaluator::do_apply( const escrow_transfer_operation& o ) {
try {
FC_ASSERT( false, "Escrow transfer operation not enabled" );
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_9 ) ); /// TODO: remove this after HF9

const auto& from_account = db().get_account(o.from);
db().get_account(o.to);
const auto& agent_account = db().get_account(o.agent);
void escrow_transfer_evaluator::do_apply( const escrow_transfer_operation& o )
{
try
{
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_14__143 ) ); /// TODO: remove this after HF14

FC_ASSERT( db().get_balance( from_account, o.amount.symbol ) >= (o.amount + o.fee) );
const auto& from_account = db().get_account(o.from);
db().get_account(o.to);
const auto& agent_account = db().get_account(o.agent);

if( o.fee.amount > 0 ) {
db().adjust_balance( from_account, -o.fee );
db().adjust_balance( agent_account, o.fee );
}
FC_ASSERT( db().get_balance( from_account, o.amount.symbol ) >= (o.amount + o.fee) );

db().adjust_balance( from_account, -o.amount );
if( o.fee.amount > 0 )
{
db().adjust_balance( from_account, -o.fee );
db().adjust_balance( agent_account, o.fee );
}

db().create<escrow_object>([&]( escrow_object& esc ) {
esc.escrow_id = o.escrow_id;
esc.from = o.from;
esc.to = o.to;
esc.agent = o.agent;
esc.balance = o.amount;
esc.expiration = o.expiration;
});
db().adjust_balance( from_account, -o.amount );

} FC_CAPTURE_AND_RETHROW( (o) ) }
db().create<escrow_object>([&]( escrow_object& esc )
{
esc.escrow_id = o.escrow_id;
esc.from = o.from;
esc.to = o.to;
esc.agent = o.agent;
esc.balance = o.amount;
esc.expiration = o.expiration;
});
}
FC_CAPTURE_AND_RETHROW( (o) )
}

void escrow_dispute_evaluator::do_apply( const escrow_dispute_operation& o ) {
try {
FC_ASSERT( false, "Escrow dispute operation not enabled" );
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_9 ) ); /// TODO: remove this after HF9
const auto& from_account = db().get_account(o.from);
void escrow_dispute_evaluator::do_apply( const escrow_dispute_operation& o )
{
try
{
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_14__143 ) ); /// TODO: remove this after HF14
const auto& from_account = db().get_account(o.from);

const auto& e = db().get_escrow( o.from, o.escrow_id );
FC_ASSERT( !e.disputed );
FC_ASSERT( e.to == o.to );
const auto& e = db().get_escrow( o.from, o.escrow_id );
FC_ASSERT( !e.disputed );
FC_ASSERT( e.to == o.to );

db().modify( e, [&]( escrow_object& esc ){
esc.disputed = true;
});
} FC_CAPTURE_AND_RETHROW( (o) ) }
db().modify( e, [&]( escrow_object& esc )
{
esc.disputed = true;
});
}
FC_CAPTURE_AND_RETHROW( (o) )
}

void escrow_release_evaluator::do_apply( const escrow_release_operation& o ) {
try {
FC_ASSERT( false, "Escrow release operation not enabled" );
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_9 ) ); /// TODO: remove this after HF9
void escrow_release_evaluator::do_apply( const escrow_release_operation& o )
{
try
{
FC_ASSERT( db().has_hardfork( STEEMIT_HARDFORK_0_14__143 ) ); /// 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& 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& 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
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() ) {
if( o.who == e.from ) FC_ASSERT( o.to == e.to );
else if( o.who == e.to ) FC_ASSERT( o.to == e.from );
else {
FC_ASSERT( e.disputed && o.who == e.agent );
if( e.expiration > db().head_block_time() )
{
if( o.who == e.from )
{
FC_ASSERT( o.to == e.to );
}
else if( o.who == e.to )
{
FC_ASSERT( o.to == e.from );
}
else
{
FC_ASSERT( e.disputed && o.who == e.agent );
}
}
else
{
FC_ASSERT( o.who == e.to || o.who == e.from );
}
} else {
FC_ASSERT( o.who == e.to || o.who == e.from );
}

db().adjust_balance( to_account, o.amount );
if( e.balance == o.amount )
db().remove( e );
else {
db().modify( e, [&]( escrow_object& esc ) {
esc.balance -= o.amount;
});
db().adjust_balance( to_account, o.amount );

if( e.balance == o.amount )
{
db().remove( e );
}
else
{
db().modify( e, [&]( escrow_object& esc )
{
esc.balance -= o.amount;
});
}
}
} FC_CAPTURE_AND_RETHROW( (o) ) }
FC_CAPTURE_AND_RETHROW( (o) )
}

void transfer_evaluator::do_apply( const transfer_operation& o )
{
Expand Down

0 comments on commit bf15b77

Please sign in to comment.