-
Notifications
You must be signed in to change notification settings - Fork 2
/
legacy.go
46 lines (40 loc) · 1.18 KB
/
legacy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package v2
import (
"context"
"math/big"
"github.com/PositionExchange/posichain/eth/rpc"
"github.com/PositionExchange/posichain/hmy"
internal_common "github.com/PositionExchange/posichain/internal/common"
)
// PublicLegacyService provides an API to access the Harmony blockchain.
// Services here are legacy methods, specific to the V1 RPC that can be deprecated in the future.
type PublicLegacyService struct {
hmy *hmy.Harmony
}
// NewPublicLegacyAPI creates a new API for the RPC interface
func NewPublicLegacyAPI(hmy *hmy.Harmony, namespace string) rpc.API {
if namespace == "" {
namespace = "hmyv2"
}
return rpc.API{
Namespace: namespace,
Version: "1.0",
Service: &PublicLegacyService{hmy},
Public: true,
}
}
// GetBalance returns the amount of Atto for the given address in the state of the
// given block number.
func (s *PublicLegacyService) GetBalance(
ctx context.Context, address string,
) (*big.Int, error) {
addr, err := internal_common.ParseAddr(address)
if err != nil {
return nil, err
}
balance, err := s.hmy.GetBalance(ctx, addr, rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber))
if err != nil {
return nil, err
}
return balance, nil
}