@@ -10,6 +10,7 @@ import (
10
10
"bytes"
11
11
"context"
12
12
"encoding/hex"
13
+ "fmt"
13
14
"math"
14
15
"math/big"
15
16
"net"
@@ -162,11 +163,24 @@ func NewServer(
162
163
163
164
// GetAccount returns the metadata of an account
164
165
func (api * Server ) GetAccount (ctx context.Context , in * iotexapi.GetAccountRequest ) (* iotexapi.GetAccountResponse , error ) {
166
+ height := uint64 (0 )
167
+ if len (in .Address ) > 41 {
168
+ heightInt , _ := strconv .Atoi (in .Address [41 :])
169
+ height = uint64 (heightInt )
170
+ in .Address = in .Address [:41 ]
171
+ }
172
+
165
173
if in .Address == address .RewardingPoolAddr || in .Address == address .StakingBucketPoolAddr {
166
- return api .getProtocolAccount (ctx , in .Address )
174
+ return api .getProtocolAccount (ctx , height , in .Address )
167
175
}
168
176
169
- state , tipHeight , err := accountutil .AccountStateWithHeight (api .sf , in .Address )
177
+ var sr protocol.StateReader = api .sf
178
+ if height != 0 {
179
+ sr = factory .NewHistoryStateReader (api .sf , height )
180
+ }
181
+ fmt .Println (height , in .Address )
182
+ //factory.NewHistoryStateReader(api.sf, rp.GetEpochHeight(inputEpochNum)
183
+ state , tipHeight , err := accountutil .AccountStateWithHeight (sr , in .Address )
170
184
if err != nil {
171
185
return nil , status .Error (codes .NotFound , err .Error ())
172
186
}
@@ -1574,7 +1588,7 @@ func (api *Server) getProductivityByEpoch(
1574
1588
return num , produce , nil
1575
1589
}
1576
1590
1577
- func (api * Server ) getProtocolAccount (ctx context.Context , addr string ) (ret * iotexapi.GetAccountResponse , err error ) {
1591
+ func (api * Server ) getProtocolAccount (ctx context.Context , height uint64 , addr string ) (ret * iotexapi.GetAccountResponse , err error ) {
1578
1592
var req * iotexapi.ReadStateRequest
1579
1593
var balance string
1580
1594
var out * iotexapi.ReadStateResponse
@@ -1583,6 +1597,7 @@ func (api *Server) getProtocolAccount(ctx context.Context, addr string) (ret *io
1583
1597
req = & iotexapi.ReadStateRequest {
1584
1598
ProtocolID : []byte ("rewarding" ),
1585
1599
MethodName : []byte ("TotalBalance" ),
1600
+ Height : fmt .Sprintf ("%d" , height ),
1586
1601
}
1587
1602
out , err = api .ReadState (ctx , req )
1588
1603
if err != nil {
@@ -1613,6 +1628,7 @@ func (api *Server) getProtocolAccount(ctx context.Context, addr string) (ret *io
1613
1628
ProtocolID : []byte ("staking" ),
1614
1629
MethodName : methodName ,
1615
1630
Arguments : [][]byte {arg },
1631
+ Height : fmt .Sprintf ("%d" , height ),
1616
1632
}
1617
1633
out , err = api .ReadState (ctx , req )
1618
1634
if err != nil {
@@ -1625,12 +1641,24 @@ func (api *Server) getProtocolAccount(ctx context.Context, addr string) (ret *io
1625
1641
balance = acc .GetBalance ()
1626
1642
}
1627
1643
1644
+ header , err := api .bc .BlockHeaderByHeight (height )
1645
+ if err != nil {
1646
+ return nil , status .Error (codes .NotFound , err .Error ())
1647
+ }
1648
+ hash := header .HashBlock ()
1649
+ //return &iotexapi.GetAccountResponse{AccountMeta: accountMeta, BlockIdentifier: &iotextypes.BlockIdentifier{
1650
+ // Hash: hex.EncodeToString(hash[:]),
1651
+ // Height: tipHeight,
1652
+ //}}
1628
1653
ret = & iotexapi.GetAccountResponse {
1629
1654
AccountMeta : & iotextypes.AccountMeta {
1630
1655
Address : addr ,
1631
1656
Balance : balance ,
1632
1657
},
1633
- BlockIdentifier : out .GetBlockIdentifier (),
1658
+ BlockIdentifier : & iotextypes.BlockIdentifier {
1659
+ Hash : hex .EncodeToString (hash [:]),
1660
+ Height : height ,
1661
+ },
1634
1662
}
1635
1663
return
1636
1664
}
0 commit comments