Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getNrgPrice Java API call #500

Merged
merged 4 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modApiServer/src/org/aion/api/server/ApiAion.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.aion.zero.impl.blockchain.AionPendingStateImpl;
import org.aion.zero.impl.blockchain.IAionChain;
import org.aion.zero.impl.config.CfgAion;
import org.aion.zero.impl.core.IAionBlockchain;
import org.aion.zero.impl.db.AionBlockStore;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionBlockSummary;
Expand Down Expand Up @@ -658,6 +659,19 @@ protected boolean setReportedHashrate(String hashrate, String clientId) {
return false;
}

// Returns a fully initialized NrgOracle object.
protected NrgOracle getNrgOracle(IAionChain _ac) {
IAionBlockchain bc = (IAionBlockchain)_ac.getBlockchain();
long nrgPriceDefault = CfgAion.inst().getApi().getNrg().getNrgPriceDefault();
long nrgPriceMax = CfgAion.inst().getApi().getNrg().getNrgPriceMax();

NrgOracle.Strategy oracleStrategy = NrgOracle.Strategy.SIMPLE;
if (CfgAion.inst().getApi().getNrg().isOracleEnabled())
oracleStrategy = NrgOracle.Strategy.BLK_PRICE;

return new NrgOracle(bc, nrgPriceDefault, nrgPriceMax, oracleStrategy);
}

protected long getRecommendedNrgPrice() {
if (this.nrgOracle != null)
return this.nrgOracle.getNrgPrice();
Expand Down
12 changes: 1 addition & 11 deletions modApiServer/src/org/aion/api/server/http/ApiWeb3Aion.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,7 @@ public ApiWeb3Aion(final IAionChain _ac) {
isFilterEnabled = CfgAion.inst().getApi().getRpc().isFiltersEnabled();
isSeedMode = CfgAion.inst().getConsensus().isSeed();


// instantiate nrg price oracle
IAionBlockchain bc = (IAionBlockchain)_ac.getBlockchain();
long nrgPriceDefault = CfgAion.inst().getApi().getNrg().getNrgPriceDefault();
long nrgPriceMax = CfgAion.inst().getApi().getNrg().getNrgPriceMax();

NrgOracle.Strategy oracleStrategy = NrgOracle.Strategy.SIMPLE;
if (CfgAion.inst().getApi().getNrg().isOracleEnabled())
oracleStrategy = NrgOracle.Strategy.BLK_PRICE;

this.nrgOracle = new NrgOracle(bc, nrgPriceDefault, nrgPriceMax, oracleStrategy);
this.nrgOracle = getNrgOracle(_ac);

if (isFilterEnabled) {
evtMgr = this.ac.getAionHub().getEventMgr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* This class is NOT thread-safe
* Policy: holder class (NrgOracle) should provide any concurrency guarantees it needs to
*
* NOT TESTED. DON'T USE.
*
* @author ali sharif
*/
public class NrgBlockPriceAveraging extends NrgPriceAdvisor<AionBlock, AionTransaction> {
Expand Down
Loading