From 9f1a356b733b5b6b0d935f7bf00f5e1141ae2201 Mon Sep 17 00:00:00 2001 From: flicker-harmony Date: Thu, 20 Feb 2020 00:16:58 +0300 Subject: [PATCH 1/3] Supply --- internal/hmyapi/apiv1/blockchain.go | 20 ++++++++++++++++++++ internal/hmyapi/apiv2/blockchain.go | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/internal/hmyapi/apiv1/blockchain.go b/internal/hmyapi/apiv1/blockchain.go index b3b8e7aee..ff692b8f1 100644 --- a/internal/hmyapi/apiv1/blockchain.go +++ b/internal/hmyapi/apiv1/blockchain.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + "github.com/harmony-one/harmony/consensus/reward" + "github.com/harmony-one/harmony/numeric" "math/big" "time" @@ -31,6 +33,7 @@ const ( defaultFromAddress = "0x0000000000000000000000000000000000000000" defaultBlocksPeriod = 15000 validatorsPageSize = 100 + initSupply = int64(12600000000) ) // PublicBlockChainAPI provides an API to access the Harmony blockchain. @@ -765,3 +768,20 @@ func (s *PublicBlockChainAPI) GetSuperCommittees() (*quorum.Transition, error) { } return nil, errNotBeaconChainShard } + +// GetTotalSupply .. +func (s *PublicBlockChainAPI) GetTotalSupply() (numeric.Dec, error) { + if s.b.GetShardID() == shard.BeaconChainShardID { + return numeric.NewDec(initSupply), nil + } + return numeric.NewDec(0), errNotBeaconChainShard +} + +// GetCirculatingSupply .. +func (s *PublicBlockChainAPI) GetCirculatingSupply() (numeric.Dec, error) { + if s.b.GetShardID() == shard.BeaconChainShardID { + timestamp := time.Now() + return numeric.NewDec(initSupply).Mul(reward.PercentageForTimeStamp(timestamp.Unix())), nil + } + return numeric.NewDec(0), errNotBeaconChainShard +} diff --git a/internal/hmyapi/apiv2/blockchain.go b/internal/hmyapi/apiv2/blockchain.go index 7283b8aab..c277ef7cf 100644 --- a/internal/hmyapi/apiv2/blockchain.go +++ b/internal/hmyapi/apiv2/blockchain.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/harmony-one/harmony/numeric" "math/big" "time" @@ -14,6 +15,7 @@ import ( "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/common/denominations" "github.com/harmony-one/harmony/consensus/quorum" + "github.com/harmony-one/harmony/consensus/reward" "github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/vm" @@ -31,6 +33,7 @@ const ( defaultFromAddress = "0x0000000000000000000000000000000000000000" defaultBlocksPeriod = 15000 validatorsPageSize = 100 + initSupply = int64(12600000000) ) // PublicBlockChainAPI provides an API to access the Harmony blockchain. @@ -730,3 +733,20 @@ func (s *PublicBlockChainAPI) GetSuperCommittees() (*quorum.Transition, error) { } return nil, errNotBeaconChainShard } + +// GetTotalSupply .. +func (s *PublicBlockChainAPI) GetTotalSupply() (numeric.Dec, error) { + if s.b.GetShardID() == shard.BeaconChainShardID { + return numeric.NewDec(initSupply), nil + } + return numeric.NewDec(0), errNotBeaconChainShard +} + +// GetCirculatingSupply .. +func (s *PublicBlockChainAPI) GetCirculatingSupply() (numeric.Dec, error) { + if s.b.GetShardID() == shard.BeaconChainShardID { + timestamp := time.Now() + return numeric.NewDec(initSupply).Mul(reward.PercentageForTimeStamp(timestamp.Unix())), nil + } + return numeric.NewDec(0), errNotBeaconChainShard +} From 3838d8e5fad5d8a81bbd8e0ea8b94c97c7d764dc Mon Sep 17 00:00:00 2001 From: flicker-harmony Date: Thu, 20 Feb 2020 00:34:13 +0300 Subject: [PATCH 2/3] Fix travis --- internal/hmyapi/apiv1/blockchain.go | 4 ++-- internal/hmyapi/apiv2/blockchain.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/hmyapi/apiv1/blockchain.go b/internal/hmyapi/apiv1/blockchain.go index ff692b8f1..c35ec7c8a 100644 --- a/internal/hmyapi/apiv1/blockchain.go +++ b/internal/hmyapi/apiv1/blockchain.go @@ -4,8 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/harmony-one/harmony/consensus/reward" - "github.com/harmony-one/harmony/numeric" "math/big" "time" @@ -16,6 +14,7 @@ import ( "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/common/denominations" "github.com/harmony-one/harmony/consensus/quorum" + "github.com/harmony-one/harmony/consensus/reward" "github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/vm" @@ -23,6 +22,7 @@ import ( internal_common "github.com/harmony-one/harmony/internal/common" "github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/utils" + "github.com/harmony-one/harmony/numeric" "github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/staking/network" staking "github.com/harmony-one/harmony/staking/types" diff --git a/internal/hmyapi/apiv2/blockchain.go b/internal/hmyapi/apiv2/blockchain.go index c277ef7cf..8ff9424a7 100644 --- a/internal/hmyapi/apiv2/blockchain.go +++ b/internal/hmyapi/apiv2/blockchain.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/harmony-one/harmony/numeric" "math/big" "time" @@ -23,6 +22,7 @@ import ( internal_common "github.com/harmony-one/harmony/internal/common" "github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/utils" + "github.com/harmony-one/harmony/numeric" "github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/staking/network" staking "github.com/harmony-one/harmony/staking/types" From fee8570c35b9ad9b385a52b773da8c1a3a0f7fac Mon Sep 17 00:00:00 2001 From: flicker-harmony Date: Thu, 20 Feb 2020 15:47:50 +0300 Subject: [PATCH 3/3] Remove beaconchain --- internal/hmyapi/apiv1/blockchain.go | 16 +++++----------- internal/hmyapi/apiv2/blockchain.go | 16 +++++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/internal/hmyapi/apiv1/blockchain.go b/internal/hmyapi/apiv1/blockchain.go index c35ec7c8a..abb7983cf 100644 --- a/internal/hmyapi/apiv1/blockchain.go +++ b/internal/hmyapi/apiv1/blockchain.go @@ -770,18 +770,12 @@ func (s *PublicBlockChainAPI) GetSuperCommittees() (*quorum.Transition, error) { } // GetTotalSupply .. -func (s *PublicBlockChainAPI) GetTotalSupply() (numeric.Dec, error) { - if s.b.GetShardID() == shard.BeaconChainShardID { - return numeric.NewDec(initSupply), nil - } - return numeric.NewDec(0), errNotBeaconChainShard +func (s *PublicBlockChainAPI) GetTotalSupply() numeric.Dec { + return numeric.NewDec(initSupply) } // GetCirculatingSupply .. -func (s *PublicBlockChainAPI) GetCirculatingSupply() (numeric.Dec, error) { - if s.b.GetShardID() == shard.BeaconChainShardID { - timestamp := time.Now() - return numeric.NewDec(initSupply).Mul(reward.PercentageForTimeStamp(timestamp.Unix())), nil - } - return numeric.NewDec(0), errNotBeaconChainShard +func (s *PublicBlockChainAPI) GetCirculatingSupply() numeric.Dec { + timestamp := time.Now() + return numeric.NewDec(initSupply).Mul(reward.PercentageForTimeStamp(timestamp.Unix())) } diff --git a/internal/hmyapi/apiv2/blockchain.go b/internal/hmyapi/apiv2/blockchain.go index 8ff9424a7..bba4a566c 100644 --- a/internal/hmyapi/apiv2/blockchain.go +++ b/internal/hmyapi/apiv2/blockchain.go @@ -735,18 +735,12 @@ func (s *PublicBlockChainAPI) GetSuperCommittees() (*quorum.Transition, error) { } // GetTotalSupply .. -func (s *PublicBlockChainAPI) GetTotalSupply() (numeric.Dec, error) { - if s.b.GetShardID() == shard.BeaconChainShardID { - return numeric.NewDec(initSupply), nil - } - return numeric.NewDec(0), errNotBeaconChainShard +func (s *PublicBlockChainAPI) GetTotalSupply() numeric.Dec { + return numeric.NewDec(initSupply) } // GetCirculatingSupply .. -func (s *PublicBlockChainAPI) GetCirculatingSupply() (numeric.Dec, error) { - if s.b.GetShardID() == shard.BeaconChainShardID { - timestamp := time.Now() - return numeric.NewDec(initSupply).Mul(reward.PercentageForTimeStamp(timestamp.Unix())), nil - } - return numeric.NewDec(0), errNotBeaconChainShard +func (s *PublicBlockChainAPI) GetCirculatingSupply() numeric.Dec { + timestamp := time.Now() + return numeric.NewDec(initSupply).Mul(reward.PercentageForTimeStamp(timestamp.Unix())) }