-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add open api for account info. (#21)
* Add open api for account info. * Return `count` info instead of `display flag`.
- Loading branch information
Showing
8 changed files
with
161 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/gin-gonic/gin" | ||
"github.com/pkg/errors" | ||
"github.com/shopspring/decimal" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func getAccountInfo(c *gin.Context) (interface{}, error) { | ||
addressInfo, err := getAddressInfo(c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addr := common.HexToAddress(addressInfo.address) | ||
balance, err := sdk.Eth.Balance(addr, nil) | ||
if err != nil { | ||
logrus.WithError(err).WithField("address", addressInfo.address).Error("Failed to get balance") | ||
return nil, errors.Errorf("Get balance error, address %v", addressInfo.address) | ||
} | ||
|
||
submitStat, err := db.AddressSubmitStore.Count(&addressInfo.addressId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rewardStat, err := db.AddressRewardStore.Count(&addressInfo.addressId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
accountInfo := AccountInfo{ | ||
Balance: decimal.NewFromBigInt(balance, 0), | ||
FileCount: submitStat.FileCount, | ||
TxCount: submitStat.TxCount, | ||
DataSize: submitStat.DataSize, | ||
StorageFee: submitStat.BaseFee, | ||
RewardCount: rewardStat.RewardCount, | ||
} | ||
|
||
return accountInfo, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters