-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from MinterTeam/dev
v0.8.0
- Loading branch information
Showing
71 changed files
with
4,484 additions
and
1,978 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/MinterTeam/minter-go-node/core/types" | ||
"github.com/MinterTeam/minter-go-node/rpc/lib/types" | ||
"math/big" | ||
) | ||
|
||
type AddressResponse struct { | ||
Balance map[string]*big.Int `json:"balance"` | ||
TransactionCount uint64 `json:"transaction_count"` | ||
} | ||
|
||
func Address(address types.Address, height int) (*AddressResponse, error) { | ||
cState, err := GetStateForHeight(height) | ||
if err != nil { | ||
return nil, &rpctypes.RPCError{Code: 404, Message: "State at given height not found", Data: err.Error()} | ||
} | ||
|
||
response := AddressResponse{ | ||
Balance: make(map[string]*big.Int), | ||
TransactionCount: cState.GetNonce(address), | ||
} | ||
|
||
balances := cState.GetBalances(address) | ||
|
||
for k, v := range balances.Data { | ||
response.Balance[k.String()] = v | ||
} | ||
|
||
if _, exists := response.Balance[types.GetBaseCoin().String()]; !exists { | ||
response.Balance[types.GetBaseCoin().String()] = big.NewInt(0) | ||
} | ||
|
||
return &response, nil | ||
} |
Oops, something went wrong.