Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 11 files changed
  • 0 commit comments
  • 2 contributors
View
14 include/bts/blockchain/blockchain_db.hpp
@@ -18,15 +18,21 @@ namespace bts { namespace blockchain {
*/
struct trx_eval
{
- trx_eval():coindays_destroyed(0),total_spent(0){}
+ trx_eval()
+ :coindays_destroyed(0),
+ invalid_coindays_destroyed(0),
+ total_spent(0){}
+
asset fees; // any fees that would be generated
uint64_t coindays_destroyed;
+ uint64_t invalid_coindays_destroyed;
uint64_t total_spent;
trx_eval& operator += ( const trx_eval& e )
{
- fees += e.fees;
- coindays_destroyed += e.coindays_destroyed;
- total_spent += e.total_spent;
+ fees += e.fees;
+ coindays_destroyed += e.coindays_destroyed;
+ invalid_coindays_destroyed += e.invalid_coindays_destroyed;
+ total_spent += e.total_spent;
return *this;
}
};
View
15 include/bts/blockchain/blockchain_market_db.hpp
@@ -29,6 +29,16 @@ namespace bts { namespace blockchain {
};
bool operator < ( const market_order& a, const market_order& b );
bool operator == ( const market_order& a, const market_order& b );
+
+ struct margin_call
+ {
+ margin_call( const price& callp, const output_reference& loc ):call_price(callp),location(loc){}
+
+ price call_price;
+ output_reference location;
+ };
+ bool operator < ( const margin_call& a, const margin_call& b );
+ bool operator == ( const margin_call& a, const margin_call& b );
/**
* Manages the current state of the market to enable effecient
@@ -43,11 +53,15 @@ namespace bts { namespace blockchain {
void open( const fc::path& db_dir );
std::vector<market_order> get_bids( asset::type quote_unit, asset::type base_unit )const;
std::vector<market_order> get_asks( asset::type quote_unit, asset::type base_unit )const;
+ std::vector<margin_call> get_calls( price call_price )const;
+
void insert_bid( const market_order& m );
void insert_ask( const market_order& m );
void remove_bid( const market_order& m );
void remove_ask( const market_order& m );
+ void insert_call( const margin_call& c );
+ void remove_call( const margin_call& c );
/** @pre quote > base */
fc::optional<market_order> get_highest_bid( asset::type quote, asset::type base );
@@ -61,3 +75,4 @@ namespace bts { namespace blockchain {
} } // bts::blockchain
FC_REFLECT( bts::blockchain::market_order, (base_unit)(quote_unit)(ratio)(location) );
+FC_REFLECT( bts::blockchain::margin_call, (call_price)(location) )
View
16 include/bts/blockchain/outputs.hpp
@@ -141,19 +141,15 @@ struct claim_by_cover_output
{
static const claim_type_enum type;
- claim_by_cover_output( const asset& payoff, const address& own )
- :payoff_unit(payoff.unit),
- payoff_amount(payoff.get_rounded_amount()),
- owner(own){}
+ claim_by_cover_output( const asset& pay, const address& own )
+ :payoff(pay), owner(own){}
- claim_by_cover_output()
- :payoff_amount(0){}
+ claim_by_cover_output(){}
- asset get_payoff_amount()const { return asset( payoff_amount, payoff_unit); }
+ price get_call_price( asset collat )const;
bool operator == ( const claim_by_cover_output& other )const;
- asset_type payoff_unit;
- uint64_t payoff_amount;
+ asset payoff;
bts::address owner;
};
@@ -324,7 +320,7 @@ FC_REFLECT( bts::blockchain::claim_by_signature_output, (owner) )
FC_REFLECT( bts::blockchain::claim_by_pts_output, (owner) )
FC_REFLECT( bts::blockchain::claim_by_bid_output, (pay_address)(ask_price) )
FC_REFLECT( bts::blockchain::claim_by_long_output, (pay_address)(ask_price) )
-FC_REFLECT( bts::blockchain::claim_by_cover_output, (payoff_unit)(payoff_amount)(owner) )
+FC_REFLECT( bts::blockchain::claim_by_cover_output, (payoff)(owner) )
FC_REFLECT( bts::blockchain::claim_by_opt_execute_output, (optionor)(expire_time)(strike_unit)(strike_amount)(optionee) )
FC_REFLECT( bts::blockchain::claim_by_escrow_output, (agreement)(agent_terms)(agent)(payee)(payor) )
FC_REFLECT( bts::blockchain::claim_by_multi_sig_output, (required)(addresses) )
View
1  include/bts/blockchain/trx_validation_state.hpp
@@ -74,6 +74,7 @@ namespace bts { namespace blockchain {
*/
const signed_transaction trx; // TODO make reference?
uint64_t total_cdd;
+ uint64_t uncounted_cdd;
uint32_t prev_block_id1; // block ids that count for CDD
uint32_t prev_block_id2; // block ids that count for CDD
View
1  include/bts/momentum.hpp
@@ -3,7 +3,6 @@
#include <fc/io/varint.hpp>
#include <fc/crypto/ripemd160.hpp>
#include <fc/reflect/reflect.hpp>
-#include <fc/crypto/sha256.hpp>
#define MOMENTUM_NONCE_BITS 26
#define MAX_MOMENTUM_NONCE (1<<MOMENTUM_NONCE_BITS)
View
198 src/blockchain/blockchain_db.cpp
@@ -86,6 +86,12 @@ namespace bts { namespace blockchain {
market_order order( cbl.ask_price, o );
_market_db.remove_bid( order );
}
+ if( trx_out.claim_func == claim_by_cover )
+ {
+ auto cbc = trx_out.as<claim_by_cover_output>();
+ margin_call order( cbc.get_call_price( trx_out.amount ), o );
+ _market_db.remove_call( order );
+ }
}
@@ -135,6 +141,11 @@ namespace bts { namespace blockchain {
elog( "Insert Short Ask: ${bid}", ("bid",market_order(cbl.ask_price, output_reference( t.id(), i )) ) );
_market_db.insert_bid( market_order(cbl.ask_price, output_reference( t.id(), i )) );
}
+ else if( t.outputs[i].claim_func == claim_by_cover )
+ {
+ auto cbc = t.outputs[i].as<claim_by_cover_output>();
+ _market_db.insert_call( margin_call( cbc.get_call_price(t.outputs[i].amount), output_reference( t.id(), i ) ) );
+ }
}
}
@@ -405,10 +416,10 @@ namespace bts { namespace blockchain {
"", ("bid", working_bid) );
}
} // while( ... )
- ilog( "." );
+
+ // We are done with all of the asks, but not the bids as margin calls may use the bids...
if( has_change && working_ask.amount.get_rounded_amount() > 0 )
{
- ilog( "." );
FC_ASSERT( ask_itr != asks.end() );
if( pay_asker.amount > 0 )
{
@@ -417,10 +428,180 @@ namespace bts { namespace blockchain {
market_trx.outputs.push_back( trx_output( claim_by_signature_output( ask_payout_address ), pay_asker ) );
}
}
+
+ //=================== START MARGIN CALL SECTION ==========================
+ if( base == asset::bts && bid_itr != bids.rend())
+ {
+ price call_price;
+ if( working_bid.claim_func == claim_by_long )
+ call_price = working_bid.as<claim_by_long_output>().ask_price;
+ else
+ call_price = working_bid.as<claim_by_bid_output>().ask_price;
+
+ // all of these margin positions must accept the highest bid
+ auto margin_positions = _market_db.get_calls( call_price );
+ ilog( "\n\nMARGIN POSITIONS:\n${p}\n\n", ("p", margin_positions ) );
+
+ trx_output working_call;
+ claim_by_cover_output cover;
+
+ auto call_itr = margin_positions.begin();
+ if( call_itr != margin_positions.end() )
+ {
+ working_call = get_output( call_itr->location );
+ cover = working_call.as<claim_by_cover_output>();
+ }
+
+ while( call_itr != margin_positions.end() &&
+ bid_itr != bids.rend() )
+ {
+ has_change = true;
+ if( working_bid.claim_func == claim_by_bid_output::type )
+ {
+ auto bid_out = working_bid.as<claim_by_bid_output>();
+ auto max_collat_purchase = working_call.amount * bid_out.ask_price;
+ bid_payout_address = bid_out.pay_address;
+ if( working_bid.amount.get_rounded_amount() >= cover.payoff.get_rounded_amount() )
+ {
+ // then the bid has enough USD... but is there enough collateral to purchase it
+ auto consumed_margin = cover.payoff * bid_out.ask_price;
+ if( max_collat_purchase.get_rounded_amount() > working_bid.amount.get_rounded_amount() )
+ { // we have fully covered the collateral position and can pay off the change
+
+ // TODO: charge a 5% fee..
+ market_trx.outputs.push_back( trx_output( claim_by_signature_output( cover.owner ),
+ working_call.amount - consumed_margin ) );
+
+ working_bid.amount -= consumed_margin * bid_out.ask_price;
+ pay_bidder += consumed_margin;
+ }
+ else // we have run out of collateral... there is no change to the short
+ {
+ working_bid.amount -= max_collat_purchase;
+ pay_bidder += max_collat_purchase * bid_out.ask_price;
+ }
+
+ market_trx.inputs.push_back( call_itr->location );
+ ++call_itr;
+ if( call_itr != margin_positions.end() )
+ {
+ working_call = get_output( call_itr->location );
+ cover = working_call.as<claim_by_cover_output>();
+ }
+ continue;
+ }
+ else // consume all of the bid, leave margin position as change
+ {
+ if( max_collat_purchase >= working_bid.amount )
+ {
+ pay_bidder += working_bid.amount * bid_out.ask_price;
+ cover.payoff -= working_bid.amount;
+ working_call.amount -= working_bid.amount * bid_out.ask_price;
+
+ market_trx.inputs.push_back( bid_itr->location );
+ market_trx.outputs.push_back( trx_output( claim_by_signature_output( bid_out.pay_address ),
+ pay_bidder) );
+
+ ++bid_itr;
+ if( bid_itr != bids.rend() ) working_bid = get_output( bid_itr->location );
+ }
+ else // we lack sufficient collateral... I guess we only consume part of the bid
+ {
+ pay_bidder += max_collat_purchase * bid_out.ask_price;
+ working_bid.amount -= max_collat_purchase;
+ market_trx.inputs.push_back( call_itr->location );
+ ++call_itr;
+ if( call_itr != margin_positions.end() )
+ {
+ working_call = get_output( call_itr->location );
+ cover = working_call.as<claim_by_cover_output>();
+ }
+ }
+ }
+ }
+ else // claim_func == claim_by_long...
+ {
+ auto long_claim = working_bid.as<claim_by_long_output>();
+ auto max_collat_purchase = working_call.amount * long_claim.ask_price;
+ auto avail_usd = working_bid.amount * long_claim.ask_price;
+ bid_payout_address = long_claim.pay_address;
+ if( avail_usd.get_rounded_amount() >= cover.payoff.get_rounded_amount() )
+ { // then the bid has enough USD... but is there enough collateral to purchase it
+ if( max_collat_purchase.get_rounded_amount() >= avail_usd.get_rounded_amount() )
+ { // then we have enough collateral to accept the full bid
+ loan_amount += avail_usd;
+ collateral_amount += working_bid.amount + working_bid.amount;
+ working_call.amount -= working_bid.amount;
+ cover.payoff -= avail_usd;
+
+ market_trx.inputs.push_back( bid_itr->location );
+ market_trx.outputs.push_back(
+ trx_output( claim_by_cover_output( loan_amount, long_claim.pay_address ), collateral_amount) );
+
+ loan_amount = asset(ULLCONST(0),loan_amount.unit);
+ collateral_amount = asset();
+ ++bid_itr;
+ if( bid_itr != bids.rend() ) working_bid = get_output( bid_itr->location );
+ }
+ else // we don't actually have enough collateral to accept the full bid
+ {
+ // consume all of the collateral... leaving what is left of the bid
+ loan_amount += max_collat_purchase;
+ collateral_amount += working_call.amount + working_call.amount;
+ working_bid.amount -= working_call.amount;
+
+ ++call_itr;
+ if( call_itr != margin_positions.end() )
+ {
+ working_call = get_output( call_itr->location );
+ cover = working_call.as<claim_by_cover_output>();
+ }
+ }
+ }
+ else // consume all of the margin...
+ {
+ cover.payoff -= avail_usd;
+ working_call.amount -= working_bid.amount;
+
+ loan_amount += avail_usd;
+ working_bid.amount -= working_bid.amount;
+
+ market_trx.inputs.push_back( call_itr->location );
+ // TODO: charge a 5% fee..
+ market_trx.outputs.push_back( trx_output( claim_by_signature_output( cover.owner ),
+ working_call.amount ) );
+ ++call_itr;
+ if( call_itr != margin_positions.end() )
+ {
+ working_call = get_output( call_itr->location );
+ cover = working_call.as<claim_by_cover_output>();
+ }
+ }
+ }
+ } // loop over margin positions..
+
+ if( margin_positions.end() != call_itr ) //
+ {
+ auto orig = get_output(call_itr->location);
+ if( orig.amount != working_call.amount )
+ {
+ // then we have some change in the margin call... apparently there
+ // were not enough bids...
+ market_trx.inputs.push_back( call_itr->location );
+ market_trx.outputs.push_back( trx_output( cover, working_call.amount ) );
+ }
+ }
+ }
+ //================ END MARGIN CALL SECTION ===============================
+
+
+
+ ilog( "has change ${C} working_bid ${b}", ("C",has_change)( "b",working_bid ) );
+
if( has_change && working_bid.amount.get_rounded_amount() > 0 )
{
- ilog( "." );
FC_ASSERT( bid_itr != bids.rend() );
+ ilog( "collateral_amount ${c}", ("c", collateral_amount ) );
if( collateral_amount.get_rounded_amount() > 0 )
{
market_trx.inputs.push_back( bid_itr->location );
@@ -429,6 +610,7 @@ namespace bts { namespace blockchain {
}
else if( working_bid.claim_func == claim_by_bid )
{
+ ilog( "pay bidder ${b}", ("b",pay_bidder) );
if( pay_bidder.get_rounded_amount() > 0 )
{
market_trx.inputs.push_back( bid_itr->location );
@@ -436,6 +618,10 @@ namespace bts { namespace blockchain {
market_trx.outputs.push_back( trx_output( claim_by_signature_output( bid_payout_address ), pay_bidder ) );
}
}
+ else
+ {
+ ilog( "\n\n SOMETHING WENT WRONG \n\n" );
+ }
}
wlog( "Market Transaction: ${trx}", ("trx", market_trx) );
@@ -669,6 +855,7 @@ namespace bts { namespace blockchain {
}
e.total_spent += vstate.balance_sheet[asset::bts].in.get_rounded_amount() + vstate.balance_sheet[asset::bts].collat_in.get_rounded_amount();
e.coindays_destroyed = vstate.total_cdd;
+ e.invalid_coindays_destroyed = vstate.uncounted_cdd;
return e;
} FC_RETHROW_EXCEPTIONS( warn, "error evaluating transaction ${t}", ("t", trx) );
}
@@ -838,6 +1025,7 @@ namespace bts { namespace blockchain {
asset total_fees;
uint64_t total_cdd = 0;
+ uint64_t invalid_cdd = 0;
uint64_t total_spent = 0;
std::unordered_set<output_reference> consumed_outputs;
@@ -873,6 +1061,7 @@ namespace bts { namespace blockchain {
("cdd",stats[i].eval.coindays_destroyed) );
total_fees += stats[i].eval.fees;
total_cdd += stats[i].eval.coindays_destroyed;
+ invalid_cdd += stats[i].eval.invalid_coindays_destroyed;
total_spent += stats[i].eval.total_spent;
}
}
@@ -919,7 +1108,8 @@ namespace bts { namespace blockchain {
new_blk.avail_coindays = my->head_block.avail_coindays
- total_cdd
+ my->head_block.total_shares - total_spent
- - total_fees.get_rounded_amount();
+ - total_fees.get_rounded_amount()
+ - invalid_cdd;
new_blk.trx_mroot = new_blk.calculate_merkle_root();
View
52 src/blockchain/blockchain_market_db.cpp
@@ -13,6 +13,7 @@ namespace bts { namespace blockchain {
public:
db::level_pod_map<market_order,uint32_t> _bids;
db::level_pod_map<market_order,uint32_t> _asks;
+ db::level_pod_map<margin_call,uint32_t> _calls;
};
} // namespace detail
@@ -44,6 +45,24 @@ namespace bts { namespace blockchain {
return a.location < b.location;
}
+
+ bool operator < ( const margin_call& a, const margin_call& b )
+ {
+ if( a.call_price.quote_unit == b.call_price.quote_unit )
+ {
+ if( a.call_price == b.call_price )
+ {
+ return a.location < b.location;
+ }
+ return b.call_price < a.call_price; // sort from high to low
+ }
+ return a.call_price.quote_unit < b.call_price.quote_unit;
+ }
+ bool operator == ( const margin_call& a, const margin_call& b )
+ {
+ return a.call_price.ratio == b.call_price.ratio && a.call_price.quote_unit == b.call_price.quote_unit && b.location == a.location;
+ }
+
market_db::market_db()
:my( new detail::market_db_impl() )
{
@@ -54,13 +73,13 @@ namespace bts { namespace blockchain {
void market_db::open( const fc::path& db_dir )
{ try {
-
fc::create_directories( db_dir / "bids" );
fc::create_directories( db_dir / "asks" );
+ fc::create_directories( db_dir / "calls" );
my->_bids.open( db_dir / "bids" );
my->_asks.open( db_dir / "asks" );
-
+ my->_calls.open( db_dir / "calls" );
} FC_RETHROW_EXCEPTIONS( warn, "unable to open market db ${dir}", ("dir",db_dir) ) }
void market_db::insert_bid( const market_order& m )
@@ -79,6 +98,14 @@ namespace bts { namespace blockchain {
{
my->_asks.remove(m);
}
+ void market_db::insert_call( const margin_call& c )
+ {
+ my->_calls.store( c, 0 );
+ }
+ void market_db::remove_call( const margin_call& c )
+ {
+ my->_calls.remove( c );
+ }
/** @pre quote > base */
fc::optional<market_order> market_db::get_highest_bid( asset::type quote, asset::type base )
@@ -120,6 +147,27 @@ namespace bts { namespace blockchain {
ilog( "order_itr is not valid!" );
return orders;
}
+
+ std::vector<margin_call> market_db::get_calls( price call_price )const
+ {
+ ilog( "get_calls price: ${p}", ("p",call_price) );
+ std::vector<margin_call> calls;
+
+ auto order_itr = my->_calls.begin();//lower_bound( margin_call( call_price, output_reference() ) );
+ while( order_itr.valid() )
+ {
+ auto call = order_itr.key();
+ ilog( "call ${c}", ("c",call) );
+ if( call.call_price.quote_unit != call_price.quote_unit )
+ return calls;
+ if( call.call_price < call_price )
+ return calls;
+ calls.push_back(call);
+ ++order_itr;
+ }
+ return calls;
+ }
+
std::vector<market_order> market_db::get_asks( asset::type quote_unit, asset::type base_unit )const
{
FC_ASSERT( quote_unit > base_unit );
View
10 src/blockchain/blockchain_outputs.cpp
@@ -46,8 +46,14 @@ namespace bts { namespace blockchain {
bool claim_by_cover_output::operator == ( const claim_by_cover_output& other )const
{
return (other.owner == owner) &&
- (other.payoff_unit == payoff_unit) &&
- abs( (int64_t(other.payoff_amount) - int64_t(payoff_amount)) ) <= 1000;
+ (other.payoff.unit == payoff.unit) &&
+ (other.payoff.get_rounded_amount() == payoff.get_rounded_amount() );
}
+ price claim_by_cover_output::get_call_price( asset collat )const
+ {
+ collat.amount *= 3;
+ collat.amount /= 4;
+ return payoff / collat;
+ }
} } // bts::blockchain
View
2  src/blockchain/blockchain_printer.cpp
@@ -43,7 +43,7 @@ namespace bts { namespace blockchain {
{
claim_by_cover_output cover = o.as<claim_by_cover_output>();
ss << "owner: "<<std::string(cover.owner)<<"<br/>\n";
- ss << "payoff: "<<std::string(cover.get_payoff_amount())<<"<br/>\n";
+ ss << "payoff: "<<std::string(cover.payoff)<<"<br/>\n";
break;
}
}
View
21 src/blockchain/blockchain_wallet.cpp
@@ -118,10 +118,9 @@ namespace bts { namespace blockchain {
if( itr->second.claim_func == claim_by_cover )
{
auto cbc = itr->second.as<claim_by_cover_output>();
- if( cbc.payoff_unit == unit )
+ if( cbc.payoff.unit == unit )
{
- asset payoff( cbc.payoff_amount, unit );
- total_due += payoff;
+ total_due += cbc.payoff;
total_collat += itr->second.amount;
}
}
@@ -143,10 +142,10 @@ namespace bts { namespace blockchain {
if( itr->second.claim_func == claim_by_cover )
{
auto cbc = itr->second.as<claim_by_cover_output>();
- if( cbc.payoff_unit == min_amnt.unit )
+ if( cbc.payoff.unit == min_amnt.unit )
{
- asset payoff( cbc.payoff_amount, min_amnt.unit );
- inputs.insert( std::pair<price,trx_input>( payoff / itr->second.amount, trx_input( _output_index_to_ref[itr->first] ) ) );
+ //asset payoff( cbc.payoff_amount, min_amnt.unit );
+ inputs.insert( std::pair<price,trx_input>( cbc.payoff / itr->second.amount, trx_input( _output_index_to_ref[itr->first] ) ) );
}
}
@@ -157,7 +156,7 @@ namespace bts { namespace blockchain {
{
auto out = get_cover_output( ritr->second.output_ref );
auto cover_out = out.as<claim_by_cover_output>();
- asset payoff( cover_out.payoff_amount, cover_out.payoff_unit );
+ asset payoff = cover_out.payoff;//( cover_out.payoff_amount, cover_out.payoff_unit );
total_payoff += payoff;
total_collat += out.amount;
@@ -557,7 +556,7 @@ namespace bts { namespace blockchain {
auto txout = my->get_cover_output( itr->output_ref );
auto cover_out = txout.as<claim_by_cover_output>();
- asset payoff( cover_out.payoff_amount, cover_out.payoff_unit );
+ asset payoff = cover_out.payoff;//( cover_out.payoff_amount, cover_out.payoff_unit );
wlog( "Payoff ${amnt} Collateral ${c}", ("amnt",amnt)("c",txout.amount) );
@@ -916,13 +915,13 @@ namespace bts { namespace blockchain {
std::cerr<<fc::variant(itr->second.claim_func).as_string()<<" ";
auto cover = itr->second.as<claim_by_cover_output>();
- auto payoff = asset(cover.payoff_amount,cover.payoff_unit);
- auto payoff_threshold = asset(uint64_t(cover.payoff_amount*double(1.5)*COIN),cover.payoff_unit);
+ auto payoff = cover.payoff;//asset(cover.payoff_amount,cover.payoff_unit);
+ auto payoff_threshold = cover.get_call_price( itr->second.amount ); //asset(uint64_t(cover.payoff_amount*double(1.5)*COIN),cover.payoff_unit);
std::cerr<< std::string(payoff);
std::cerr<< " owner: ";
std::cerr<< std::string(itr->second.as<claim_by_cover_output>().owner);
// this is the break even price... we actually need to cover at half the price?
- std::cerr<< " price: " << std::string(payoff_threshold / itr->second.amount);
+ std::cerr<< " price: " << std::string(payoff_threshold);
std::cerr<<"\n";
break;
}
View
23 src/blockchain/trx_validation_state.cpp
@@ -9,7 +9,7 @@
namespace bts { namespace blockchain {
trx_validation_state::trx_validation_state( const signed_transaction& t, blockchain_db* d, bool enf, uint32_t h )
-:prev_block_id1(0),prev_block_id2(0),trx(t),total_cdd(0),balance_sheet( asset::count ),db(d),enforce_unspent(enf),ref_head(h)
+:prev_block_id1(0),prev_block_id2(0),trx(t),total_cdd(0),uncounted_cdd(0),balance_sheet( asset::count ),db(d),enforce_unspent(enf),ref_head(h)
{
inputs = d->fetch_inputs( t.inputs, ref_head );
if( ref_head == std::numeric_limits<uint32_t>::max() )
@@ -213,16 +213,16 @@ void trx_validation_state::validate_cover( const trx_output& o )
{
auto cover_claim = o.as<claim_by_cover_output>();
try {
- auto payoff_unit = (asset::type)cover_claim.payoff_unit;
+ auto payoff_unit = (asset::type)cover_claim.payoff.unit;
balance_sheet[(asset::type)o.amount.unit].out += o.amount;
- balance_sheet[payoff_unit].neg_out += cover_claim.get_payoff_amount();
- if( balance_sheet[(asset::type)cover_claim.payoff_unit].collat_in != asset() )
+ balance_sheet[payoff_unit].neg_out += cover_claim.payoff;
+ if( balance_sheet[payoff_unit].collat_in != asset() )
{
auto req_price = balance_sheet[payoff_unit].collat_in / balance_sheet[payoff_unit].neg_in;
// TODO: verify this should be <= instead of >=
- FC_ASSERT( req_price >= o.amount / cover_claim.get_payoff_amount(), "",
- ("req_price",req_price)( "amnt", o.amount )( "payoff", cover_claim.get_payoff_amount())("new_price",
- o.amount / cover_claim.get_payoff_amount() ));
+ FC_ASSERT( req_price >= o.amount / cover_claim.payoff, "",
+ ("req_price",req_price)( "amnt", o.amount )( "payoff", cover_claim.payoff)("new_price",
+ o.amount / cover_claim.payoff ));
}
} FC_RETHROW_EXCEPTIONS( warn, "${cover}", ("cover",cover_claim) ) }
@@ -275,6 +275,7 @@ void trx_validation_state::validate_signature( const meta_trx_input& in )
}
else
{
+ uncounted_cdd += in.output.amount.get_rounded_amount() * (ref_head-in.source.block_num);
wlog( "stake ${s} != ${a} || ${b}", ("s",trx.stake)("a",prev_block_id1)("b",prev_block_id2) );
}
}
@@ -414,14 +415,18 @@ void trx_validation_state::validate_cover( const meta_trx_input& in )
auto cover_in = in.output.as<claim_by_cover_output>();
balance_sheet[(asset::type)in.output.amount.unit].in += in.output.amount;
- balance_sheet[(asset::type)cover_in.payoff_unit].neg_in += cover_in.get_payoff_amount();
+ balance_sheet[(asset::type)cover_in.payoff.unit].neg_in += cover_in.payoff;
// track collateral for payoff unit
- balance_sheet[(asset::type)cover_in.payoff_unit].collat_in += in.output.amount;
+ balance_sheet[(asset::type)cover_in.payoff.unit].collat_in += in.output.amount;
if( trx.stake == prev_block_id1 || trx.stake == prev_block_id2 )
{
total_cdd += in.output.amount.get_rounded_amount() * (ref_head-in.source.block_num);
}
+ else
+ {
+ uncounted_cdd += in.output.amount.get_rounded_amount() * (ref_head-in.source.block_num);
+ }
}
void trx_validation_state::validate_opt( const meta_trx_input& in )

No commit comments for this range

Something went wrong with that request. Please try again.