You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
4 years ago
|
package v1
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||
|
"github.com/ethereum/go-ethereum/rpc"
|
||
|
"github.com/harmony-one/harmony/hmy"
|
||
|
internal_common "github.com/harmony-one/harmony/internal/common"
|
||
|
)
|
||
|
|
||
|
// PublicEthService provides an API to access to the Eth endpoints for the Harmony blockchain.
|
||
|
type PublicEthService struct {
|
||
|
hmy *hmy.Harmony
|
||
|
}
|
||
|
|
||
|
// NewPublicEthService creates a new API for the RPC interface
|
||
|
func NewPublicEthService(hmy *hmy.Harmony, namespace string) rpc.API {
|
||
|
if namespace == "" {
|
||
|
namespace = "eth"
|
||
|
}
|
||
|
|
||
|
return rpc.API{
|
||
|
Namespace: namespace,
|
||
|
Version: "1.0",
|
||
|
Service: &PublicEthService{hmy},
|
||
|
Public: true,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// GetBalance returns the amount of Atto for the given address in the state of the
|
||
|
// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
|
||
|
// block numbers are also allowed.
|
||
|
func (s *PublicEthService) GetBalance(
|
||
|
ctx context.Context, address string, blockNr rpc.BlockNumber,
|
||
|
) (*hexutil.Big, error) {
|
||
|
addr := internal_common.ParseAddr(address)
|
||
|
balance, err := s.hmy.GetBalance(ctx, addr, blockNr)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return (*hexutil.Big)(balance), nil
|
||
|
}
|