Skip to content

Commit

Permalink
Create 'EnrichedSmartState' interface. (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov authored Aug 27, 2024
1 parent 4be1228 commit 57fa6c7
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 84 deletions.
4 changes: 2 additions & 2 deletions pkg/ride/diff_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (b changedAccounts) addAssetBalanceChange(account proto.AddressID, asset cr
}

type diffState struct {
state types.SmartState
state types.EnrichedSmartState
data map[dataEntryKey]proto.DataEntry
wavesBalances map[proto.AddressID]diffBalance
assetBalances map[assetBalanceKey]assetBalance
Expand All @@ -209,7 +209,7 @@ type diffState struct {
changedAccounts changedAccounts
}

func newDiffState(state types.SmartState) diffState {
func newDiffState(state types.EnrichedSmartState) diffState {
return diffState{
state: state,
data: map[dataEntryKey]proto.DataEntry{},
Expand Down
19 changes: 8 additions & 11 deletions pkg/ride/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ type WrappedState struct {
rootActionsCountValidator proto.ActionsCountValidator
}

func newWrappedState(env *EvaluationEnvironment, rootScriptLibVersion ast.LibraryVersion) *WrappedState {
func newWrappedState(
env *EvaluationEnvironment,
originalStateForWrappedState types.EnrichedSmartState,
rootScriptLibVersion ast.LibraryVersion,
) *WrappedState {
return &WrappedState{
diff: newDiffState(env.st),
diff: newDiffState(originalStateForWrappedState),
cle: env.th.(rideAddress),
scheme: env.sch,
height: proto.Height(env.height()),
Expand Down Expand Up @@ -381,14 +385,6 @@ func (ws *WrappedState) NewestBlockInfoByHeight(height proto.Height) (*proto.Blo
return ws.diff.state.NewestBlockInfoByHeight(height)
}

func (ws *WrappedState) WavesBalanceProfile(id proto.AddressID) (*types.WavesBalanceProfile, error) {
return ws.diff.state.WavesBalanceProfile(id)
}

func (ws *WrappedState) NewestAssetBalanceByAddressID(id proto.AddressID, asset crypto.Digest) (uint64, error) {
return ws.diff.state.NewestAssetBalanceByAddressID(id, asset)
}

func (ws *WrappedState) validateAsset(action proto.ScriptAction, asset proto.OptionalAsset, env environment) (bool, error) {
if !asset.Present {
return true, nil
Expand Down Expand Up @@ -1092,14 +1088,15 @@ func NewEnvironment(

func NewEnvironmentWithWrappedState(
env *EvaluationEnvironment,
originalState types.EnrichedSmartState,
payments proto.ScriptPayments,
sender proto.WavesAddress,
isProtobufTransaction bool,
rootScriptLibVersion ast.LibraryVersion,
checkSenderBalance bool,
) (*EvaluationEnvironment, error) {
recipient := proto.WavesAddress(env.th.(rideAddress))
st := newWrappedState(env, rootScriptLibVersion)
st := newWrappedState(env, originalState, rootScriptLibVersion)
for i, payment := range payments {
var (
senderBalance uint64
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type txAppender struct {
}

func newTxAppender(
state types.SmartState,
state types.EnrichedSmartState,
rw *blockReadWriter,
stor *blockchainEntitiesStorage,
settings *settings.BlockchainSettings,
Expand Down
2 changes: 1 addition & 1 deletion pkg/state/ethereum_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/wavesplatform/gowaves/pkg/types"
)

func defaultTxAppender(t *testing.T, storage scriptStorageState, state types.SmartState,
func defaultTxAppender(t *testing.T, storage scriptStorageState, state types.EnrichedSmartState,
assetsUncertain map[proto.AssetID]wrappedUncertainInfo,
params *appendTxParams) txAppender {
scheme := proto.TestNetScheme
Expand Down
10 changes: 5 additions & 5 deletions pkg/state/script_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type scriptCaller struct {
state types.SmartState
state types.EnrichedSmartState

stor *blockchainEntitiesStorage
settings *settings.BlockchainSettings
Expand All @@ -24,7 +24,7 @@ type scriptCaller struct {
}

func newScriptCaller(
state types.SmartState,
state types.EnrichedSmartState,
stor *blockchainEntitiesStorage,
settings *settings.BlockchainSettings,
) (*scriptCaller, error) {
Expand Down Expand Up @@ -362,7 +362,7 @@ func (a *scriptCaller) invokeFunctionByInvokeWithProofsTx(
// Since V5 we have to create environment with wrapped state to which we put attached payments
if tree.LibVersion >= ast.LibV5 {
isPbTx := proto.IsProtobufTx(tx)
env, err = ride.NewEnvironmentWithWrappedState(env, tx.Payments, sender, isPbTx, tree.LibVersion, true)
env, err = ride.NewEnvironmentWithWrappedState(env, a.state, tx.Payments, sender, isPbTx, tree.LibVersion, true)
if err != nil {
return nil, proto.FunctionCall{}, errors.Wrapf(err, "failed to create RIDE environment with wrapped state")
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func (a *scriptCaller) invokeFunctionByEthereumTx(
//TODO: Update last argument of the followinxg call with new feature activation flag or
// something else depending on NODE-2531 issue resolution in scala implementation.
isPbTx := proto.IsProtobufTx(tx)
env, err = ride.NewEnvironmentWithWrappedState(env, scriptPayments, sender, isPbTx, tree.LibVersion, false)
env, err = ride.NewEnvironmentWithWrappedState(env, a.state, scriptPayments, sender, isPbTx, tree.LibVersion, false)
if err != nil {
return nil, proto.FunctionCall{}, errors.Wrap(err, "failed to create RIDE environment with wrapped state")
}
Expand Down Expand Up @@ -456,7 +456,7 @@ func (a *scriptCaller) invokeFunctionByInvokeExpressionWithProofsTx(
// Since V5 we have to create environment with wrapped state to which we put attached payments
if tree.LibVersion >= ast.LibV5 {
isPbTx := proto.IsProtobufTx(tx)
env, err = ride.NewEnvironmentWithWrappedState(env, payments, sender, isPbTx, tree.LibVersion, true)
env, err = ride.NewEnvironmentWithWrappedState(env, a.state, payments, sender, isPbTx, tree.LibVersion, true)
if err != nil {
return nil, errors.Wrapf(err, "failed to create RIDE environment with wrapped state")
}
Expand Down
Loading

0 comments on commit 57fa6c7

Please sign in to comment.