-
Notifications
You must be signed in to change notification settings - Fork 30
Deprecate the conditional route handlers #1497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
enlight
wants to merge
6
commits into
master
Choose a base branch
from
new-tx-router
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d100149
Deprecate the conditional route handlers
enlight 72c797c
Remove blank line
enlight d9e1d7d
Use an on-chain config setting to enable the new routing behavior
enlight 97b7d58
Fix test & add a new one
enlight 4d3f404
Merge branch 'master' into new-tx-router
enlight 3cc3e22
Fix build
enlight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,75 @@ | ||
| package tx_handler | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/gogo/protobuf/proto" | ||
| "github.com/loomnetwork/go-loom" | ||
| "github.com/loomnetwork/loomchain" | ||
| "github.com/loomnetwork/loomchain/auth" | ||
| "github.com/loomnetwork/loomchain/eth/utils" | ||
| "github.com/loomnetwork/loomchain/vm" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // CallTxHandler handles txs that call Go & EVM contracts | ||
| type CallTxHandler struct { | ||
| *vm.Manager | ||
| } | ||
|
|
||
| func (h *CallTxHandler) ProcessTx( | ||
| state loomchain.State, | ||
| txBytes []byte, | ||
| isCheckTx bool, | ||
| ) (loomchain.TxHandlerResult, error) { | ||
| var r loomchain.TxHandlerResult | ||
|
|
||
| var msg vm.MessageTx | ||
| if err := proto.Unmarshal(txBytes, &msg); err != nil { | ||
| return r, err | ||
| } | ||
|
|
||
| origin := auth.Origin(state.Context()) | ||
| caller := loom.UnmarshalAddressPB(msg.From) | ||
| addr := loom.UnmarshalAddressPB(msg.To) | ||
|
|
||
| if caller.Compare(origin) != 0 { | ||
| return r, fmt.Errorf("Origin doesn't match caller: %v != %v", origin, caller) | ||
| } | ||
|
|
||
| // TODO: move the marshalling & validation above this line into middleware | ||
| var tx vm.CallTx | ||
| if err := proto.Unmarshal(msg.Data, &tx); err != nil { | ||
| return r, err | ||
| } | ||
|
|
||
| switch tx.VmType { | ||
| case vm.VMType_EVM: | ||
| r.Info = utils.CallEVM | ||
| // Only do basic validation of EVM calls in CheckTx, don't execute the actual call | ||
| if isCheckTx { | ||
| return r, nil | ||
| } | ||
|
|
||
| case vm.VMType_PLUGIN: | ||
| r.Info = utils.CallPlugin | ||
|
|
||
| default: | ||
| return r, errors.New("invalid vm type") | ||
| } | ||
|
|
||
| vmInstance, err := h.Manager.InitVM(tx.VmType, state) | ||
| if err != nil { | ||
| return r, err | ||
| } | ||
|
|
||
| var value *loom.BigUInt | ||
| if tx.Value == nil { | ||
| value = loom.NewBigUIntFromInt(0) | ||
| } else { | ||
| value = &tx.Value.Value | ||
| } | ||
|
|
||
| r.Data, err = vmInstance.Call(origin, addr, tx.Input, value) | ||
| return r, err | ||
| } |
This file contains hidden or 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,103 @@ | ||
| package tx_handler | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/gogo/protobuf/proto" | ||
| "github.com/loomnetwork/go-loom" | ||
| "github.com/loomnetwork/go-loom/types" | ||
| "github.com/loomnetwork/loomchain" | ||
| "github.com/loomnetwork/loomchain/auth" | ||
| "github.com/loomnetwork/loomchain/eth/utils" | ||
| registry "github.com/loomnetwork/loomchain/registry/factory" | ||
| "github.com/loomnetwork/loomchain/vm" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // DeployTxHandler handles txs that deploy Go & EVM contracts | ||
| type DeployTxHandler struct { | ||
| *vm.Manager | ||
| CreateRegistry registry.RegistryFactoryFunc | ||
| AllowNamedEVMContracts bool | ||
| } | ||
|
|
||
| func (h *DeployTxHandler) ProcessTx( | ||
| state loomchain.State, | ||
| txBytes []byte, | ||
| isCheckTx bool, | ||
| ) (loomchain.TxHandlerResult, error) { | ||
| var r loomchain.TxHandlerResult | ||
|
|
||
| var msg vm.MessageTx | ||
| if err := proto.Unmarshal(txBytes, &msg); err != nil { | ||
| return r, err | ||
| } | ||
|
|
||
| origin := auth.Origin(state.Context()) | ||
| caller := loom.UnmarshalAddressPB(msg.From) | ||
|
|
||
| if caller.Compare(origin) != 0 { | ||
| return r, fmt.Errorf("Origin doesn't match caller: - %v != %v", origin, caller) | ||
| } | ||
|
|
||
| // TODO: move the marshalling & validation above this line into middleware | ||
| var tx vm.DeployTx | ||
| if err := proto.Unmarshal(msg.Data, &tx); err != nil { | ||
| return r, err | ||
| } | ||
|
|
||
| switch tx.VmType { | ||
| case vm.VMType_EVM: | ||
| r.Info = utils.DeployEvm | ||
|
|
||
| if (len(tx.Name) > 0) && !h.AllowNamedEVMContracts { | ||
| return r, errors.New("named evm contracts are not allowed") | ||
| } | ||
|
|
||
| // Only do basic validation of EVM deploys in CheckTx, don't execute the actual deploy | ||
| if isCheckTx { | ||
| return r, nil | ||
| } | ||
|
|
||
| case vm.VMType_PLUGIN: | ||
| r.Info = utils.DeployPlugin | ||
|
|
||
| default: | ||
| return r, errors.New("invalid vm type") | ||
| } | ||
|
|
||
| vmInstance, err := h.Manager.InitVM(tx.VmType, state) | ||
| if err != nil { | ||
| return r, err | ||
| } | ||
|
|
||
| var value *loom.BigUInt | ||
| if tx.Value == nil { | ||
| value = loom.NewBigUIntFromInt(0) | ||
| } else { | ||
| value = &tx.Value.Value | ||
| } | ||
|
|
||
| retCreate, addr, err := vmInstance.Create(origin, tx.Code, value) | ||
| if err != nil { | ||
| return r, errors.Wrapf(err, "failed to create contract") | ||
| } | ||
|
|
||
| response, err := proto.Marshal(&vm.DeployResponse{ | ||
| Contract: &types.Address{ | ||
| ChainId: addr.ChainID, | ||
| Local: addr.Local, | ||
| }, | ||
| Output: retCreate, | ||
| }) | ||
| if err != nil { | ||
| return r, errors.Wrapf(err, "failed to marshal deploy response") | ||
| } | ||
| r.Data = response | ||
|
|
||
| reg := h.CreateRegistry(state) | ||
| if err := reg.Register(tx.Name, addr, caller); err != nil { | ||
| return r, err | ||
| } | ||
| return r, nil | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.