Skip to content

Commit

Permalink
Merge pull request #5107 from multiversx/update-master-rc-v1.5.0-2023…
Browse files Browse the repository at this point in the history
….03.20

Update master rc v1.5.0 2023.03.20
  • Loading branch information
iulianpascalau authored Mar 20, 2023
2 parents a862099 + aa453b9 commit 46aac83
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.1.33
github.com/multiversx/mx-chain-crypto-go v1.2.5
github.com/multiversx/mx-chain-es-indexer-go v1.3.13
github.com/multiversx/mx-chain-es-indexer-go v1.3.14
github.com/multiversx/mx-chain-logger-go v1.0.11
github.com/multiversx/mx-chain-p2p-go v1.0.10
github.com/multiversx/mx-chain-storage-go v1.0.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ github.com/multiversx/mx-chain-core-go v1.1.33 h1:qk+TlaOhHpu+9VncL3yowjY4KU8uJ0
github.com/multiversx/mx-chain-core-go v1.1.33/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk=
github.com/multiversx/mx-chain-crypto-go v1.2.5 h1:tuq3BUNMhKud5DQbZi9DiVAAHUXypizy8zPH0NpTGZk=
github.com/multiversx/mx-chain-crypto-go v1.2.5/go.mod h1:teqhNyWEqfMPgNn8sgWXlgtJ1a36jGCnhs/tRpXW6r4=
github.com/multiversx/mx-chain-es-indexer-go v1.3.13 h1:n32q0Xe6YfUIjfK3ryKe70WnsBQseaDrwb2tGDpTTAk=
github.com/multiversx/mx-chain-es-indexer-go v1.3.13/go.mod h1:IV42GfhkqQ5vVO0OzGaF/ejp8TQrLkNo4LSB3TPnVhg=
github.com/multiversx/mx-chain-es-indexer-go v1.3.14 h1:cDaBsY8i2PuCQZ6DMf3LgxB0ocErM3TWlKGGzGqGX7E=
github.com/multiversx/mx-chain-es-indexer-go v1.3.14/go.mod h1:IV42GfhkqQ5vVO0OzGaF/ejp8TQrLkNo4LSB3TPnVhg=
github.com/multiversx/mx-chain-logger-go v1.0.11 h1:DFsHa+sc5fKwhDR50I8uBM99RTDTEW68ESyr5ALRDwE=
github.com/multiversx/mx-chain-logger-go v1.0.11/go.mod h1:1srDkP0DQucWQ+rYfaq0BX2qLnULsUdRPADpYUTM6dA=
github.com/multiversx/mx-chain-p2p-go v1.0.10 h1:CYCuI0SP8Pt9K0TcJjUyxK7ByvWi2FXNUihy0iCEVIA=
Expand Down
66 changes: 57 additions & 9 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,11 @@ func (n *Node) GetConsensusGroupSize() int {
func (n *Node) GetBalance(address string, options api.AccountQueryOptions) (*big.Int, api.BlockInfo, error) {
userAccount, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
apiBlockInfo, ok := extractApiBlockInfoIfErrAccountNotFoundAtBlock(err)
if ok {
return big.NewInt(0), apiBlockInfo, nil
}
if err == ErrCannotCastAccountHandlerToUserAccountHandler {
return big.NewInt(0), api.BlockInfo{}, nil
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return big.NewInt(0), adaptedBlockInfo, nil
}

return nil, api.BlockInfo{}, err
}

Expand All @@ -174,6 +172,11 @@ func (n *Node) GetBalance(address string, options api.AccountQueryOptions) (*big
func (n *Node) GetUsername(address string, options api.AccountQueryOptions) (string, api.BlockInfo, error) {
userAccount, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return "", adaptedBlockInfo, nil
}

return "", api.BlockInfo{}, err
}

Expand All @@ -185,6 +188,11 @@ func (n *Node) GetUsername(address string, options api.AccountQueryOptions) (str
func (n *Node) GetCodeHash(address string, options api.AccountQueryOptions) ([]byte, api.BlockInfo, error) {
userAccount, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return make([]byte, 0), adaptedBlockInfo, nil
}

return nil, api.BlockInfo{}, err
}

Expand All @@ -200,6 +208,7 @@ func (n *Node) GetAllIssuedESDTs(tokenType string, ctx context.Context) ([]strin

userAccount, _, err := n.loadUserAccountHandlerByPubKey(vm.ESDTSCAddress, api.AccountQueryOptions{})
if err != nil {
// don't return 0 values here - not finding the ESDT SC address is an error that should be returned
return nil, err
}

Expand Down Expand Up @@ -277,6 +286,11 @@ func (n *Node) getEsdtDataFromLeaf(leaf core.KeyValueHolder, userAccount state.U
func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, ctx context.Context) (map[string]string, api.BlockInfo, error) {
userAccount, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return make(map[string]string), adaptedBlockInfo, nil
}

return nil, api.BlockInfo{}, err
}

Expand Down Expand Up @@ -331,6 +345,11 @@ func (n *Node) GetValueForKey(address string, key string, options api.AccountQue

userAccount, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return "", adaptedBlockInfo, nil
}

return "", api.BlockInfo{}, err
}

Expand All @@ -347,6 +366,13 @@ func (n *Node) GetESDTData(address, tokenID string, nonce uint64, options api.Ac
// TODO: refactor here as to ensure userAccount and systemAccount are on the same root-hash
userAccount, _, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return &esdt.ESDigitalToken{
Value: big.NewInt(0),
}, adaptedBlockInfo, nil
}

return nil, api.BlockInfo{}, err
}

Expand Down Expand Up @@ -512,6 +538,11 @@ func (n *Node) GetAllESDTTokens(address string, options api.AccountQueryOptions,
// TODO: refactor here as to ensure userAccount and systemAccount are on the same root-hash
userAccount, _, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return make(map[string]*esdt.ESDigitalToken), adaptedBlockInfo, nil
}

return nil, api.BlockInfo{}, err
}

Expand Down Expand Up @@ -839,13 +870,13 @@ func (n *Node) CreateTransaction(
func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) {
account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options)
if err != nil {
apiBlockInfo, ok := extractApiBlockInfoIfErrAccountNotFoundAtBlock(err)
if ok {
adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err)
if isEmptyAccount {
return api.AccountResponse{
Address: address,
Balance: "0",
DeveloperReward: "0",
}, apiBlockInfo, nil
}, adaptedBlockInfo, nil
}

return api.AccountResponse{}, api.BlockInfo{}, err
Expand All @@ -870,6 +901,23 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.
}, blockInfo, nil
}

func extractBlockInfoIfNewAccount(err error) (api.BlockInfo, bool) {
if err == nil {
return api.BlockInfo{}, true
}

apiBlockInfo, ok := extractApiBlockInfoIfErrAccountNotFoundAtBlock(err)
if ok {
return apiBlockInfo, true
}
// we need this check since (in some situations) this error is also returned when a nil account handler is passed (empty account)
if err == ErrCannotCastAccountHandlerToUserAccountHandler {
return api.BlockInfo{}, true
}

return api.BlockInfo{}, false
}

// GetCode returns the code for the given code hash
func (n *Node) GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) {
return n.loadAccountCode(codeHash, options)
Expand Down
Loading

0 comments on commit 46aac83

Please sign in to comment.