Skip to content

Commit

Permalink
Merge pull request #5547 from multiversx/extend-altered-account-struc…
Browse files Browse the repository at this point in the history
…ture

Extra fields
  • Loading branch information
miiu96 authored Sep 6, 2023
2 parents 23457b1 + e052cd1 commit e71fb0a
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.0.6
github.com/multiversx/mx-chain-core-go v1.2.14
github.com/multiversx/mx-chain-core-go v1.2.15
github.com/multiversx/mx-chain-crypto-go v1.2.8
github.com/multiversx/mx-chain-es-indexer-go v1.4.10
github.com/multiversx/mx-chain-es-indexer-go v1.4.11
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-scenario-go v1.2.1
github.com/multiversx/mx-chain-storage-go v1.0.12
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
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.14 h1:TAfJ3aUcT54JCWtmfsSvzsVEQKfLZ0Di0bZG6XoXc1w=
github.com/multiversx/mx-chain-core-go v1.2.14/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-core-go v1.2.15 h1:2qbcGP9yHi9CFeLF9xTDnDPJjvafvTmwEkitfI0wWME=
github.com/multiversx/mx-chain-core-go v1.2.15/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU=
github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8=
github.com/multiversx/mx-chain-es-indexer-go v1.4.10 h1:qwYWQ92PuaKhrhZEHm+blEeYSvrxtT1rG8sAL4OEzqc=
github.com/multiversx/mx-chain-es-indexer-go v1.4.10/go.mod h1:rgsFY2RwaH5Slud0i6zJbxidvf1y8LE+YOXnnny0O/c=
github.com/multiversx/mx-chain-es-indexer-go v1.4.11 h1:fL/PdXaUXMt7S12gRvTZKs2dhVOVFm24wUcNTiCYKvM=
github.com/multiversx/mx-chain-es-indexer-go v1.4.11/go.mod h1:4HIWP7q8+yee/W28s4CtpjgrIXPlPeojDTa5qUVDHO8=
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=
github.com/multiversx/mx-chain-scenario-go v1.2.1 h1:9eC6VcOEAKRRKZ7EbSWPLzCdNIMWwuNBtAZlgR4cSMA=
Expand Down
7 changes: 7 additions & 0 deletions node/external/blockAPI/metaBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ func (mbp *metaAPIBlockProcessor) convertMetaBlockBytesToAPIBlock(hash []byte, b
Timestamp: time.Duration(blockHeader.GetTimeStamp()),
StateRootHash: hex.EncodeToString(blockHeader.RootHash),
Status: BlockStatusOnChain,
PubKeyBitmap: hex.EncodeToString(blockHeader.GetPubKeysBitmap()),
Signature: hex.EncodeToString(blockHeader.GetSignature()),
LeaderSignature: hex.EncodeToString(blockHeader.GetLeaderSignature()),
ChainID: string(blockHeader.GetChainID()),
SoftwareVersion: hex.EncodeToString(blockHeader.GetSoftwareVersion()),
ReceiptsHash: hex.EncodeToString(blockHeader.GetReceiptsHash()),
Reserved: blockHeader.GetReserved(),
}

addScheduledInfoInBlock(blockHeader, apiMetaBlock)
Expand Down
14 changes: 14 additions & 0 deletions node/external/blockAPI/metaBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ func TestMetaAPIBlockProcessor_GetBlockByHashFromHistoryNodeStatusReverted(t *te
DeveloperFees: big.NewInt(0),
AccumulatedFeesInEpoch: big.NewInt(10),
DevFeesInEpoch: big.NewInt(5),
PubKeysBitmap: []byte("010101"),
Signature: []byte("sig"),
LeaderSignature: []byte("leader"),
ChainID: []byte("1"),
SoftwareVersion: []byte("2"),
ReceiptsHash: []byte("recHash"),
Reserved: []byte("res"),
}
headerBytes, _ := json.Marshal(header)
_ = storerMock.Put(headerHash, headerBytes)
Expand All @@ -575,6 +582,13 @@ func TestMetaAPIBlockProcessor_GetBlockByHashFromHistoryNodeStatusReverted(t *te
AccumulatedFeesInEpoch: "10",
DeveloperFeesInEpoch: "5",
Status: BlockStatusReverted,
PubKeyBitmap: "303130313031",
Signature: "736967",
LeaderSignature: "6c6561646572",
ChainID: "1",
SoftwareVersion: "32",
ReceiptsHash: "72656348617368",
Reserved: []byte("res"),
}

blk, err := metaAPIBlockProcessor.GetBlockByHash(headerHash, api.BlockQueryOptions{})
Expand Down
7 changes: 7 additions & 0 deletions node/external/blockAPI/shardBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ func (sbp *shardAPIBlockProcessor) convertShardBlockBytesToAPIBlock(hash []byte,
Timestamp: time.Duration(blockHeader.GetTimeStamp()),
Status: BlockStatusOnChain,
StateRootHash: hex.EncodeToString(blockHeader.GetRootHash()),
PubKeyBitmap: hex.EncodeToString(blockHeader.GetPubKeysBitmap()),
Signature: hex.EncodeToString(blockHeader.GetSignature()),
LeaderSignature: hex.EncodeToString(blockHeader.GetLeaderSignature()),
ChainID: string(blockHeader.GetChainID()),
SoftwareVersion: hex.EncodeToString(blockHeader.GetSoftwareVersion()),
ReceiptsHash: hex.EncodeToString(blockHeader.GetReceiptsHash()),
Reserved: blockHeader.GetReserved(),
}

addScheduledInfoInBlock(blockHeader, apiBlock)
Expand Down
14 changes: 14 additions & 0 deletions node/external/blockAPI/shardBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ func TestShardAPIBlockProcessor_GetBlockByNonceFromHistoryNode(t *testing.T) {
},
AccumulatedFees: big.NewInt(100),
DeveloperFees: big.NewInt(50),
PubKeysBitmap: []byte("010101"),
Signature: []byte("sig"),
LeaderSignature: []byte("leader"),
ChainID: []byte("1"),
SoftwareVersion: []byte("2"),
ReceiptsHash: []byte("recHash"),
Reserved: []byte("res"),
}
headerBytes, _ := json.Marshal(header)
_ = storerMock.Put(headerHash, headerBytes)
Expand All @@ -337,6 +344,13 @@ func TestShardAPIBlockProcessor_GetBlockByNonceFromHistoryNode(t *testing.T) {
AccumulatedFees: "100",
DeveloperFees: "50",
Status: BlockStatusOnChain,
PubKeyBitmap: "303130313031",
Signature: "736967",
LeaderSignature: "6c6561646572",
ChainID: "1",
SoftwareVersion: "32",
ReceiptsHash: "72656348617368",
Reserved: []byte("res"),
}

blk, err := shardAPIBlockProcessor.GetBlockByNonce(1, api.BlockQueryOptions{})
Expand Down
9 changes: 8 additions & 1 deletion outport/process/alteredaccounts/alteredAccountsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,17 @@ func (aap *alteredAccountsProvider) addAdditionalDataInAlteredAccount(alteredAcc
IsSender: markedAccount.isSender,
BalanceChanged: markedAccount.balanceChanged,
UserName: string(userAccount.GetUserName()),
CodeMetadata: userAccount.GetCodeMetadata(),
RootHash: userAccount.GetRootHash(),
}

isSC := core.IsSmartContractAddress(userAccount.AddressBytes())
if isSC {
alteredAcc.AdditionalData.CodeHash = userAccount.GetCodeHash()
}

ownerAddressBytes := userAccount.GetOwnerAddress()
if core.IsSmartContractAddress(userAccount.AddressBytes()) && len(ownerAddressBytes) == aap.addressConverter.Len() {
if isSC && len(ownerAddressBytes) == aap.addressConverter.Len() {
alteredAcc.AdditionalData.CurrentOwner = aap.addressConverter.SilentEncode(ownerAddressBytes, log)
}
developerRewards := userAccount.GetDeveloperReward()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func TestGetAlteredAccountFromUserAccount(t *testing.T) {
Owner: []byte("owner"),
UserName: []byte("contract"),
Address: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
CodeHash: []byte("hash"),
CodeMetadata: []byte("metadata"),
GetRootHashCalled: func() []byte {
return []byte("rootHash")
},
}

res := &alteredAccount.AlteredAccount{
Expand All @@ -109,6 +114,9 @@ func TestGetAlteredAccountFromUserAccount(t *testing.T) {
DeveloperRewards: "100",
CurrentOwner: "6f776e6572",
UserName: "contract",
CodeHash: []byte("hash"),
CodeMetadata: []byte("metadata"),
RootHash: []byte("rootHash"),
},
}, res)

Expand Down
8 changes: 5 additions & 3 deletions testscommon/state/userAccountStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type UserAccountStub struct {
UserName []byte
Owner []byte
Address []byte
CodeMetadata []byte
CodeHash []byte

AddToBalanceCalled func(value *big.Int) error
DataTrieTrackerCalled func() state.DataTrieTracker
Expand Down Expand Up @@ -97,7 +99,7 @@ func (u *UserAccountStub) AddressBytes() []byte {
return u.Address
}

//IncreaseNonce -
// IncreaseNonce -
func (u *UserAccountStub) IncreaseNonce(_ uint64) {
}

Expand All @@ -121,7 +123,7 @@ func (u *UserAccountStub) SetCodeMetadata(_ []byte) {

// GetCodeMetadata -
func (u *UserAccountStub) GetCodeMetadata() []byte {
return nil
return u.CodeMetadata
}

// SetCodeHash -
Expand All @@ -131,7 +133,7 @@ func (u *UserAccountStub) SetCodeHash([]byte) {

// GetCodeHash -
func (u *UserAccountStub) GetCodeHash() []byte {
return nil
return u.CodeHash
}

// SetRootHash -
Expand Down

0 comments on commit e71fb0a

Please sign in to comment.