Skip to content

Commit

Permalink
extra field accounts indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Aug 30, 2023
1 parent f7a8b23 commit bf42840
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 53 deletions.
47 changes: 24 additions & 23 deletions data/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ import (

// AccountInfo holds (serializable) data about an account
type AccountInfo struct {
Address string `json:"address,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Balance string `json:"balance"`
BalanceNum float64 `json:"balanceNum"`
TokenName string `json:"token,omitempty"`
TokenIdentifier string `json:"identifier,omitempty"`
TokenNonce uint64 `json:"tokenNonce,omitempty"`
Properties string `json:"properties,omitempty"`
Frozen bool `json:"frozen,omitempty"`
TotalBalanceWithStake string `json:"totalBalanceWithStake,omitempty"`
TotalBalanceWithStakeNum float64 `json:"totalBalanceWithStakeNum,omitempty"`
Owner string `json:"owner,omitempty"`
UserName string `json:"userName,omitempty"`
DeveloperRewards string `json:"developerRewards,omitempty"`
DeveloperRewardsNum float64 `json:"developerRewardsNum,omitempty"`
Data *TokenMetaData `json:"data,omitempty"`
Timestamp time.Duration `json:"timestamp,omitempty"`
Type string `json:"type,omitempty"`
CurrentOwner string `json:"currentOwner,omitempty"`
ShardID uint32 `json:"shardID"`
IsSender bool `json:"-"`
IsSmartContract bool `json:"-"`
IsNFTCreate bool `json:"-"`
Address string `json:"address,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Balance string `json:"balance"`
BalanceNum float64 `json:"balanceNum"`
TokenName string `json:"token,omitempty"`
TokenIdentifier string `json:"identifier,omitempty"`
TokenNonce uint64 `json:"tokenNonce,omitempty"`
Properties string `json:"properties,omitempty"`
Frozen bool `json:"frozen,omitempty"`
Owner string `json:"owner,omitempty"`
UserName string `json:"userName,omitempty"`
DeveloperRewards string `json:"developerRewards,omitempty"`
DeveloperRewardsNum float64 `json:"developerRewardsNum,omitempty"`
Data *TokenMetaData `json:"data,omitempty"`
Timestamp time.Duration `json:"timestamp,omitempty"`
Type string `json:"type,omitempty"`
CurrentOwner string `json:"currentOwner,omitempty"`
ShardID uint32 `json:"shardID"`
RootHash []byte `json:"rootHash,omitempty"`
CodeHash []byte `json:"codeHash,omitempty"`
CodeMetadata []byte `json:"codeMetadata,omitempty"`
IsSender bool `json:"-"`
IsSmartContract bool `json:"-"`
IsNFTCreate bool `json:"-"`
}

// TokenMetaData holds data about a token metadata
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-communication-go v1.0.6
github.com/multiversx/mx-chain-core-go v1.2.13
github.com/multiversx/mx-chain-core-go v1.2.15-0.20230830125719-028435cb3956
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-vm-common-go v1.5.2
github.com/prometheus/client_model v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg=
github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-core-go v1.2.13 h1:4Svi23hdsoibStFXv0i7lbBWus3kDJPc6CFhrxrKIZ4=
github.com/multiversx/mx-chain-core-go v1.2.13/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-core-go v1.2.15-0.20230830125719-028435cb3956 h1:RlIWOnzWd5zsv7SDcNMiOkvuHiXEFHcdbzvaDfpM5UU=
github.com/multiversx/mx-chain-core-go v1.2.15-0.20230830125719-028435cb3956/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
Expand Down
21 changes: 11 additions & 10 deletions process/elasticproc/accounts/accountsProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ func (ap *accountsProcessor) PrepareRegularAccountsMap(timestamp uint64, account
}

acc := &data.AccountInfo{
Address: address,
Nonce: userAccount.UserAccount.Nonce,
Balance: converters.BigIntToString(balance),
BalanceNum: balanceAsFloat,
IsSender: userAccount.IsSender,
IsSmartContract: core.IsSmartContractAddress(addressBytes),
TotalBalanceWithStake: converters.BigIntToString(balance),
TotalBalanceWithStakeNum: balanceAsFloat,
Timestamp: time.Duration(timestamp),
ShardID: shardID,
Address: address,
Nonce: userAccount.UserAccount.Nonce,
Balance: converters.BigIntToString(balance),
BalanceNum: balanceAsFloat,
IsSender: userAccount.IsSender,
IsSmartContract: core.IsSmartContractAddress(addressBytes),
Timestamp: time.Duration(timestamp),
ShardID: shardID,
}

ap.addAdditionalDataInAccount(userAccount.UserAccount.AdditionalData, acc)
Expand All @@ -150,6 +148,9 @@ func (ap *accountsProcessor) addAdditionalDataInAccount(additionalData *alteredA

account.UserName = additionalData.UserName
account.CurrentOwner = additionalData.CurrentOwner
account.RootHash = additionalData.RootHash
account.CodeHash = additionalData.CodeHash
account.CodeMetadata = additionalData.CodeMetadata

ap.addDeveloperRewardsInAccount(additionalData, account)
}
Expand Down
22 changes: 14 additions & 8 deletions process/elasticproc/accounts/accountsProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ func TestAccountsProcessor_PrepareAccountsMapEGLD(t *testing.T) {
Address: addr,
Balance: "1000",
Nonce: 1,
AdditionalData: &alteredAccount.AdditionalAccountData{
CodeHash: []byte("code"),
CodeMetadata: []byte("metadata"),
RootHash: []byte("root"),
},
}

egldAccount := &data.Account{
Expand All @@ -282,14 +287,15 @@ func TestAccountsProcessor_PrepareAccountsMapEGLD(t *testing.T) {

res := ap.PrepareRegularAccountsMap(123, []*data.Account{egldAccount}, 0)
require.Equal(t, &data.AccountInfo{
Address: addr,
Nonce: 1,
Balance: "1000",
BalanceNum: balanceNum,
TotalBalanceWithStake: "1000",
TotalBalanceWithStakeNum: balanceNum,
IsSmartContract: true,
Timestamp: time.Duration(123),
Address: addr,
Nonce: 1,
Balance: "1000",
BalanceNum: balanceNum,
IsSmartContract: true,
Timestamp: time.Duration(123),
CodeHash: []byte("code"),
CodeMetadata: []byte("metadata"),
RootHash: []byte("root"),
},
res[addr])
}
Expand Down
16 changes: 7 additions & 9 deletions process/elasticproc/accounts/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ func TestSerializeAccounts(t *testing.T) {

accs := map[string]*data.AccountInfo{
"addr1": {
Address: "addr1",
Nonce: 1,
Balance: "50",
BalanceNum: 0.1,
TotalBalanceWithStake: "50",
TotalBalanceWithStakeNum: 0.1,
IsSmartContract: true,
IsSender: true,
Address: "addr1",
Nonce: 1,
Balance: "50",
BalanceNum: 0.1,
IsSmartContract: true,
IsSender: true,
},
}

Expand All @@ -56,7 +54,7 @@ func TestSerializeAccounts(t *testing.T) {
require.Equal(t, 1, len(buffSlice.Buffers()))

expectedRes := `{ "update" : {"_index": "accounts", "_id" : "addr1" } }
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if (ctx._source.containsKey('timestamp')) {if (ctx._source.timestamp <= params.account.timestamp) {ctx._source = params.account}} else {ctx._source = params.account}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"50","balanceNum":0.1,"totalBalanceWithStake":"50","totalBalanceWithStakeNum":0.1,"shardID":0} }},"upsert": {}}
{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx._source = params.account} else {if (ctx._source.containsKey('timestamp')) {if (ctx._source.timestamp <= params.account.timestamp) {ctx._source = params.account}} else {ctx._source = params.account}}","lang": "painless","params": { "account": {"address":"addr1","nonce":1,"balance":"50","balanceNum":0.1,"shardID":0} }},"upsert": {}}
`
require.Equal(t, expectedRes, buffSlice.Buffers()[0].String())
}
Expand Down

0 comments on commit bf42840

Please sign in to comment.