Skip to content

Commit

Permalink
Merge pull request #500 from aionick/add_nrgPrice
Browse files Browse the repository at this point in the history
Add getNrgPrice Java API call
  • Loading branch information
AionJayT authored Jun 5, 2018
2 parents 8f93329 + 3467903 commit d3a9916
Show file tree
Hide file tree
Showing 5 changed files with 2,881 additions and 1,584 deletions.
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

0 comments on commit d3a9916

Please sign in to comment.