The core protocol of WoopChain
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.
woop/rpc/eth/rpc.go

47 lines
1.2 KiB

package eth
import (
"context"
"github.com/ethereum/go-ethereum/common/hexutil"
8 months ago
"github.com/woop-chain/woop/eth/rpc"
"github.com/woop-chain/woop/wiki"
internal_common "github.com/woop-chain/woop/internal/common"
)
8 months ago
// PublicEthService provides an API to access to the Eth endpoints for the Woop blockchain.
type PublicEthService struct {
8 months ago
wiki *wiki.Woop
}
// NewPublicEthService creates a new API for the RPC interface
8 months ago
func NewPublicEthService(wiki *wiki.Woop, namespace string) rpc.API {
if namespace == "" {
namespace = "eth"
}
return rpc.API{
Namespace: namespace,
Version: "1.0",
8 months ago
Service: &PublicEthService{wiki},
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, blockNrOrHash rpc.BlockNumberOrHash,
) (*hexutil.Big, error) {
addr, err := internal_common.ParseAddr(address)
if err != nil {
return nil, err
}
8 months ago
balance, err := s.wiki.GetBalance(ctx, addr, blockNrOrHash)
if err != nil {
return nil, err
}
return (*hexutil.Big)(balance), nil
}