void addline (json::value& jsonlines, ripplestate const& line, ledger::pointer ledger)
{
    stamount sabalance (line.getbalance ());
    stamount const& salimit (line.getlimit ());
    stamount const& salimitpeer (line.getlimitpeer ());
    json::value& jpeer (jsonlines.append (json::objectvalue));

    jpeer[jss::account] = to_string (line.getaccountidpeer ());
    if (assetcurrency() == sabalance.getcurrency()) {
        // calculate released & reserved balance for asset.
        auto lpledger = std::make_shared<ledger> (std::ref (*ledger), false);
        ledgerentryset les(lpledger, tapnone);
        auto sleripplestate = les.entrycache(ltripple_state, getripplestateindex(line.getaccountid(), line.getaccountidpeer(), assetcurrency()));
        les.assetrelease(line.getaccountid(), line.getaccountidpeer(), assetcurrency(), sleripplestate);
        stamount reserve = sleripplestate->getfieldamount(sfreserve);
        stamount balance = sleripplestate->getfieldamount(sfbalance);
        if (line.getaccountid() == sleripplestate->getfieldamount(sfhighlimit).getissuer()) {
            reserve.negate();
            balance.negate();
        }
        jpeer[jss::reserve] = reserve.gettext();
        jpeer[jss::balance] = balance.gettext();
    } else {
        // amount reported is positive if current account holds other
        // account's ious.
        //
        // amount reported is negative if other account holds current
        // account's ious.
        jpeer[jss::balance] = sabalance.gettext();
    }
    jpeer[jss::currency] = sabalance.gethumancurrency ();
    jpeer[jss::limit] = salimit.gettext ();
    jpeer[jss::limit_peer] = salimitpeer.gettext ();
    jpeer[jss::quality_in]
        = static_cast<json::uint> (line.getqualityin ());
    jpeer[jss::quality_out]
        = static_cast<json::uint> (line.getqualityout ());
    if (line.getauth ())
        jpeer[jss::authorized] = true;
    if (line.getauthpeer ())
        jpeer[jss::peer_authorized] = true;
    if (line.getnoripple ())
        jpeer[jss::no_ripple] = true;
    if (line.getnoripplepeer ())
        jpeer[jss::no_ripple_peer] = true;
    if (line.getfreeze ())
        jpeer[jss::freeze] = true;
    if (line.getfreezepeer ())
        jpeer[jss::freeze_peer] = true;
}
示例#2
0
void testController(){
    
    /* Initally values */
    bus clk ("P"); // Clock pulse
    bus rst ("0");
    bus go("P");
    bus gtr("1");
    bus eql("0");
    bus les("0");
    bus en_quo, ready;
    
    DividerController * DC = new DividerController(clk, rst, go, gtr, eql, les, en_quo, ready);
    
    std::cout << "The inital values:\n";
    DC->printValues();
    
    DC->eval();
    std::cout << "\nAfter evaluation:\n";
    DC->printValues();
    
    DC->eval();
    std::cout << "\nAfter evaluation:\n";
    DC->printValues();
    
    /* Next values */
    clk = "P";
    rst = "0";
    go = "0";
    gtr = "0";
    eql = "1";
    les = "0";
    
    DC->eval();
    std::cout << "\nAfter evaluation:\n";
    DC->printValues();
    
}
// {
//   account: [<account>|<account_public_key>]
//   peer: [<account>|<account_public_key>]
//   currency: <currency>
//   ledger_hash : <ledger>
//   ledger_index : <ledger_index>
// }
json::value doaccountasset (rpc::context& context)
{
    auto const& params(context.params);
    if (!params.ismember(jss::account))
        return rpc::missing_field_error("account");
    if (!params.ismember(jss::peer))
        return rpc::missing_field_error("peer");
    if (!params.ismember(jss::currency))
        return rpc::missing_field_error("currency");

    ledger::pointer ledger;
    json::value result(rpc::lookupledger(params, ledger, context.netops));
    if (!ledger)
        return result;

    std::string strident(params[jss::account].asstring());
    bool bindex(params.ismember(jss::account_index));
    int iindex(bindex ? params[jss::account_index].asuint() : 0);
    rippleaddress rippleaddress;

    json::value const jv(rpc::accountfromstring(ledger, rippleaddress, bindex,
                                                strident, iindex, false, context.netops));
    if (!jv.empty()) {
        for (json::value::const_iterator it(jv.begin()); it != jv.end(); ++it)
            result[it.membername()] = it.key();

        return result;
    }

    if (!ledger->hasaccount(rippleaddress))
        return rpcerror(rpcact_not_found);

    std::string strpeer(params.ismember(jss::peer) ? params[jss::peer].asstring() : "");
    bool bpeerindex(params.ismember(jss::peer_index));
    int ipeerindex(bindex ? params[jss::peer_index].asuint() : 0);
    rippleaddress rippleaddresspeer;

    json::value const jvpeer(rpc::accountfromstring(ledger, rippleaddresspeer, bpeerindex,
                                                    strpeer, ipeerindex, false, context.netops));
    if (!jvpeer.empty()) {
        return result;
    }

    if (!ledger->hasaccount(rippleaddresspeer))
        return rpcerror(rpcact_not_found);

    currency ucurrency;
    if (!to_currency(ucurrency, params[jss::currency].asstring()))
        return rpc::make_error(rpcsrc_cur_malformed, "invalid field 'currency', bad currency.");

    account const& raaccount(rippleaddress.getaccountid());
    account const& rapeeraccount(rippleaddresspeer.getaccountid());

    uint256 unodeindex = getripplestateindex(raaccount, rapeeraccount, ucurrency);
    auto slenode = context.netops.getslei(ledger, unodeindex);
    auto const line(ripplestate::makeitem(raaccount, slenode));

    if (line == nullptr ||
        raaccount != line->getaccountid() ||
        rapeeraccount != line->getaccountidpeer())
        return result;

    json::value jsonlines(json::arrayvalue);
    addline(jsonlines, *line, ledger);
    result[jss::lines] = jsonlines[0u];
    
    json::value& jsonassetstates(result[jss::states] = json::arrayvalue);
    
    // get asset_states for currency asset.
    if (assetcurrency() == line->getbalance().getcurrency()) {
        auto lpledger = std::make_shared<ledger> (std::ref (*ledger), false);
        ledgerentryset les(lpledger, tapnone);
        auto sleripplestate = les.entrycache(ltripple_state, getripplestateindex(raaccount, rapeeraccount, assetcurrency()));
        les.assetrelease(raaccount, rapeeraccount, assetcurrency(), sleripplestate);

        uint256 baseindex = getassetstateindex(line->getaccountid(), line->getaccountidpeer(), assetcurrency());
        uint256 assetstateindex = getqualityindex(baseindex);
        uint256 assetstateend = getqualitynext(assetstateindex);

        for (;;) {
            auto const& sle = les.entrycache(ltasset_state, assetstateindex);
            if (sle) {
                stamount amount = sle->getfieldamount(sfamount);
                stamount released = sle->getfieldamount(sfdeliveredamount);

                if (sle->getfieldaccount160(sfaccount) == line->getaccountidpeer()) {
                    amount.negate();
                    released.negate();
                }

                auto reserved = released ? amount - released : amount;

                json::value& state(jsonassetstates.append(json::objectvalue));
                state[jss::date] = static_cast<json::uint>(getquality(assetstateindex));
                state[jss::amount] = amount.gettext();
                state[jss::reserve] = reserved.gettext();
            }

            auto const nextassetstate(
                les.getnextledgerindex(assetstateindex, assetstateend));

            if (nextassetstate.iszero())
                break;

            assetstateindex = nextassetstate;
        }
    }

    context.loadtype = resource::feemediumburdenrpc;
    return result;
}
示例#4
0
void loadPointSet(const char* lidarFileName,unsigned int memCacheSize,const char* pointFileName,Scalar filterRadius,int numLobes,const Vector& pointOffset)
	{
	/* Create a color and coordinate node to receive points: */
	SceneGraph::ColorNode* color=new SceneGraph::ColorNode;
	SceneGraph::CoordinateNode* coord=new SceneGraph::CoordinateNode;
	
	/* Create the point set node: */
	SceneGraph::PointSetNode* pointSet=new SceneGraph::PointSetNode;
	pointSet->color.setValue(color);
	pointSet->coord.setValue(coord);
	pointSet->pointSize.setValue(5);
	pointSet->update();
	SceneGraph::ShapeNode* shape=new SceneGraph::ShapeNode;
	shape->geometry.setValue(pointSet);
	shape->update();
	getSceneGraphRoot().children.appendValue(shape);
	getSceneGraphRoot().update();
	
	/* Create a temporary LiDAR processing octree to calculate point elevations: */
	LidarProcessOctree lpo(lidarFileName,size_t(memCacheSize)*size_t(1024*1024));
	
	/* Open the point file: */
	IO::AutoFile pointFile(IO::openFile(pointFileName));
	IO::ValueSource pointSource(*pointFile);
	pointSource.setWhitespace("");
	pointSource.setPunctuation(",\n");
	pointSource.setQuotes("\"");
	
	/* Read the header line: */
	int valueCol=-1;
	int posCol[2]={-1,-1};
	for(int col=0;!pointSource.eof()&&pointSource.peekc()!='\n';++col)
		{
		std::string columnHeader=pointSource.readString();
		if(columnHeader=="DamageID1")
			valueCol=col;
		else if(columnHeader=="POINT_X")
			posCol[0]=col;
		else if(columnHeader=="POINT_Y")
			posCol[1]=col;
		if(pointSource.peekc()==',')
			pointSource.skipString();
		}
	
	/* Go to the next line: */
	pointSource.skipString();
	
	/* Read all points: */
	while(!pointSource.eof())
		{
		/* Read the current line: */
		double value=0.0;
		double pos[2]={0.0,0.0};
		for(int col=0;!pointSource.eof()&&pointSource.peekc()!='\n';++col)
			{
			if(col==valueCol)
				value=pointSource.readNumber();
			else if(col==posCol[0])
				pos[0]=pointSource.readNumber();
			else if(col==posCol[1])
				pos[1]=pointSource.readNumber();
			else
				pointSource.skipString();
			if(pointSource.peekc()==',')
				pointSource.skipString();
			}
		
		/* Calculate the current point's elevation: */
		LidarRadialElevationSampler les(pos,filterRadius,numLobes);
		lpo.processPointsInBox(les.getBox(),les);
		if(les.getAbsWeightSum()>0.0)
			{
			/* Add the point to the coordinate node: */
			SceneGraph::Point p;
			for(int i=0;i<2;++i)
				p[i]=SceneGraph::Scalar(pos[i]-double(pointOffset[i]));
			p[2]=SceneGraph::Scalar(les.getValue()-double(pointOffset[2]));
			coord->point.appendValue(p);
			
			if(value<2.5)
				color->color.appendValue(SceneGraph::Color(1.0f,0.0f,0.0f));
			else if(value<3.5)
				color->color.appendValue(SceneGraph::Color(1.0f,0.5f,0.0f));
			else if(value<4.5)
				color->color.appendValue(SceneGraph::Color(0.5f,1.0f,0.0f));
			else if(value<5.5)
				color->color.appendValue(SceneGraph::Color(0.0f,1.0f,0.0f));
			else
				color->color.appendValue(SceneGraph::Color(0.0f,1.0f,0.0f));
			}
		
		/* Go to the next line: */
		pointSource.skipString();
		}
	
	color->update();
	coord->update();
	}