Skip to content

Commit

Permalink
CHANGED: to use pending state in Energi info API
Browse files Browse the repository at this point in the history
  • Loading branch information
andvgal committed Feb 25, 2020
1 parent 0597e9e commit bca2f41
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
15 changes: 8 additions & 7 deletions energi/api/blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (b *BlacklistAPI) registry(
session = &energi_abi.IBlacklistRegistrySession{
Contract: contract,
CallOpts: bind.CallOpts{
Pending: true,
From: dst,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down Expand Up @@ -105,8 +106,8 @@ func (b *BlacklistAPI) blacklistInfo(num *big.Int) (interface{}, error) {
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}
addresses, err := registry.EnumerateAll(call_opts)
if err != nil {
Expand All @@ -119,29 +120,29 @@ func (b *BlacklistAPI) blacklistInfo(num *big.Int) (interface{}, error) {
for _, addr := range addresses {
blocked, err := registry.IsBlacklisted(call_opts, addr)
if err != nil {
log.Warn("IsBlacklisted error", "addr", addr, "err", err)
log.Debug("IsBlacklisted error", "addr", addr, "err", err)
continue
}

proposals, err := registry.Proposals(call_opts, addr)
if err != nil {
log.Warn("Proposals error", "addr", addr, "err", err)
log.Debug("Proposals error", "addr", addr, "err", err)
continue
}

enforceInfo, err := proposalInfo(b.backend, proposals.Enforce)
if err != nil {
log.Warn("Enforce info error", "addr", addr, "err", err)
log.Debug("Enforce info error", "addr", addr, "err", err)
}

revokeInfo, err := proposalInfo(b.backend, proposals.Revoke)
if err != nil {
log.Warn("Revoke info error", "addr", addr, "err", err)
log.Debug("Revoke info error", "addr", addr, "err", err)
}

drainInfo, err := proposalInfo(b.backend, proposals.Drain)
if err != nil {
log.Warn("Drain info error", "addr", addr, "err", err)
log.Debug("Drain info error", "addr", addr, "err", err)
}

res = append(res, BLInfo{
Expand Down
5 changes: 3 additions & 2 deletions energi/api/checkpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (b *CheckpointAPI) registry(
session = &energi_abi.ICheckpointRegistrySession{
Contract: contract,
CallOpts: bind.CallOpts{
Pending: true,
From: from,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down Expand Up @@ -128,8 +129,8 @@ func (b *CheckpointAPI) checkpointInfo(num *big.Int) (interface{}, error) {
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}
addresses, err := registry.Checkpoints(call_opts)
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions energi/api/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func proposalInfo(backend Backend, address common.Address) (*ProposalInfo, error
}

call_opts := &bind.CallOpts{
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}

Expand Down Expand Up @@ -324,8 +325,8 @@ func (g *GovernanceAPI) upgradeProposalInfo(num *big.Int, proxy common.Address)
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}
proposals, err := proxy_obj.ListUpgradeProposals(call_opts)
if err != nil {
Expand Down Expand Up @@ -368,6 +369,7 @@ func (g *GovernanceAPI) governedProxy(
session = &energi_abi.IGovernedProxySession{
Contract: contract,
CallOpts: bind.CallOpts{
Pending: true,
From: owner,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down Expand Up @@ -534,6 +536,7 @@ func (g *GovernanceAPI) treasury(
session = &energi_abi.ITreasurySession{
Contract: contract,
CallOpts: bind.CallOpts{
Pending: true,
From: payer,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down Expand Up @@ -585,8 +588,8 @@ func (g *GovernanceAPI) budgetInfo(num *big.Int) (interface{}, error) {
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}

proposals, err := treasury.ListProposals(call_opts)
Expand All @@ -605,7 +608,7 @@ func (g *GovernanceAPI) budgetInfo(num *big.Int) (interface{}, error) {
for i, p := range proposals {
pInfo, err := proposalInfo(g.backend, p)
if err != nil {
log.Error("Failed at proposalInfo", "err", err)
log.Debug("Failed at proposalInfo", "err", err)
continue
}

Expand All @@ -614,23 +617,23 @@ func (g *GovernanceAPI) budgetInfo(num *big.Int) (interface{}, error) {
budger_proposal, err := energi_abi.NewIBudgetProposalCaller(
p, g.backend.(bind.ContractCaller))
if err != nil {
log.Error("Failed at NewIBudgetProposalCaller", "err", err)
log.Debug("Failed at NewIBudgetProposalCaller", "err", err)
return nil, err
}

proposed_amount, err := budger_proposal.ProposedAmount(call_opts)
if err != nil {
log.Error("Failed ProposedAmount", "err", err)
log.Debug("Failed ProposedAmount", "err", err)
continue
}
paid_amount, err := budger_proposal.PaidAmount(call_opts)
if err != nil {
log.Error("Failed ProposedAmount", "err", err)
log.Debug("Failed ProposedAmount", "err", err)
continue
}
ref_uuid, err := budger_proposal.RefUuid(call_opts)
if err != nil {
log.Error("Failed ProposedAmount", "err", err)
log.Debug("Failed ProposedAmount", "err", err)
continue
}
ret[i].ProposedAmount = (*hexutil.Big)(proposed_amount)
Expand Down
18 changes: 10 additions & 8 deletions energi/api/masternode.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (m *MasternodeAPI) CollateralBalance(

res, err := token.BalanceInfo(
&bind.CallOpts{
Pending: true,
From: dst,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down Expand Up @@ -264,8 +265,8 @@ func (m *MasternodeAPI) listMasternodes(num *big.Int) (interface{}, error) {
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}
prev_call_opts := &bind.CallOpts{
BlockNumber: new(big.Int).Sub(num, common.Big3),
Expand All @@ -282,19 +283,19 @@ func (m *MasternodeAPI) listMasternodes(num *big.Int) (interface{}, error) {
for _, mn := range masternodes {
mninfo, err := registry.Info(call_opts, mn)
if err != nil {
log.Warn("Info error", "mn", mn, "err", err)
log.Debug("Info error", "mn", mn, "err", err)
continue
}

isActive, err := registry.IsActive(call_opts, mn)
if err != nil {
log.Warn("IsActive error", "mn", mn, "err", err)
log.Debug("IsActive error", "mn", mn, "err", err)
continue
}

canHeartbeat, err := registry.CanHeartbeat(call_opts, mn)
if err != nil {
log.Warn("CanHeartbeat error", "mn", mn, "err", err)
log.Debug("CanHeartbeat error", "mn", mn, "err", err)
continue
}

Expand All @@ -313,7 +314,7 @@ func (m *MasternodeAPI) listMasternodes(num *big.Int) (interface{}, error) {
Collateral: (*hexutil.Big)(mninfo.Collateral),
AnnouncedBlock: mninfo.AnnouncedBlock.Uint64(),
IsActive: isActive,
IsAlive: isActive && !canHeartbeat && !prevCanHeartbeat,
IsAlive: isActive && (!canHeartbeat || !prevCanHeartbeat),
SWFeatures: (*hexutil.Big)(mninfo.SwFeatures),
SWVersion: energi_common.SWVersionIntToString(mninfo.SwFeatures),
})
Expand Down Expand Up @@ -360,8 +361,8 @@ func (m *MasternodeAPI) stats(num *big.Int) (interface{}, error) {
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}
count, err := registry.Count(call_opts)
if err != nil {
Expand Down Expand Up @@ -404,6 +405,7 @@ func masternodeRegistry(
session = &energi_abi.IMasternodeRegistryV2Session{
Contract: contract,
CallOpts: bind.CallOpts{
Pending: true,
From: dst,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down
5 changes: 3 additions & 2 deletions energi/api/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (m *MigrationAPI) listGen2CoinsUncached(num *big.Int) (interface{}, error)
}

call_opts := &bind.CallOpts{
BlockNumber: num,
GasLimit: energi_params.UnlimitedGas,
Pending: true,
GasLimit: energi_params.UnlimitedGas,
}
bigItems, err := mgrt_contract.ItemCount(call_opts)
if err != nil {
Expand Down Expand Up @@ -446,6 +446,7 @@ func (m *MigrationAPI) claimGen2Coins(
mgrt_contract := energi_abi.Gen2MigrationSession{
Contract: mgrt_contract_obj,
CallOpts: bind.CallOpts{
Pending: true,
From: dst,
GasLimit: energi_params.UnlimitedGas,
},
Expand Down

0 comments on commit bca2f41

Please sign in to comment.