-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: crosschain precmpile contract (#579)
- Loading branch information
1 parent
7b5e453
commit 3c4f227
Showing
24 changed files
with
1,047 additions
and
804 deletions.
There are no files selected for viewing
This file contains 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,13 @@ | ||
package contract | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
) | ||
|
||
type PrecompileMethod interface { | ||
GetMethodId() []byte | ||
RequiredGas() uint64 | ||
IsReadonly() bool | ||
Run(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract) ([]byte, error) | ||
} |
This file contains 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 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,66 @@ | ||
package legacy | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/armon/go-metrics" | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// Fip20CrossChainEvents use for fip20 cross chain | ||
// Deprecated | ||
func Fip20CrossChainEvents(ctx sdk.Context, from, token common.Address, recipient, target, denom string, amount, fee *big.Int) { | ||
ctx.EventManager().EmitEvent(sdk.NewEvent( | ||
EventTypeRelayTransferCrossChain, | ||
sdk.NewAttribute(AttributeKeyFrom, from.String()), | ||
sdk.NewAttribute(AttributeKeyRecipient, recipient), | ||
sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()), | ||
sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), | ||
sdk.NewAttribute(AttributeKeyTarget, target), | ||
sdk.NewAttribute(AttributeKeyTokenAddress, token.String()), | ||
sdk.NewAttribute(AttributeKeyDenom, denom), | ||
)) | ||
|
||
telemetry.IncrCounterWithLabels( | ||
[]string{"relay_transfer_cross_chain"}, | ||
1, | ||
[]metrics.Label{ | ||
telemetry.NewLabel("erc20", token.String()), | ||
telemetry.NewLabel("denom", denom), | ||
telemetry.NewLabel("target", target), | ||
}, | ||
) | ||
} | ||
|
||
// CrossChainEvents | ||
// Deprecated | ||
func CrossChainEvents(ctx sdk.Context, from, token common.Address, recipient, target, denom, memo string, amount, fee *big.Int) { | ||
ctx.EventManager().EmitEvent(sdk.NewEvent( | ||
EventTypeCrossChain, | ||
sdk.NewAttribute(AttributeKeyFrom, from.String()), | ||
sdk.NewAttribute(AttributeKeyRecipient, recipient), | ||
sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()), | ||
sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), | ||
sdk.NewAttribute(AttributeKeyTarget, target), | ||
sdk.NewAttribute(AttributeKeyTokenAddress, token.String()), | ||
sdk.NewAttribute(AttributeKeyDenom, denom), | ||
sdk.NewAttribute(AttributeKeyMemo, memo), | ||
)) | ||
} | ||
|
||
const ( | ||
// EventTypeRelayTransferCrossChain | ||
// Deprecated | ||
EventTypeRelayTransferCrossChain = "relay_transfer_cross_chain" | ||
// EventTypeCrossChain new cross chain event type | ||
EventTypeCrossChain = "cross_chain" | ||
|
||
AttributeKeyDenom = "coin" | ||
AttributeKeyTokenAddress = "token_address" | ||
AttributeKeyFrom = "from" | ||
AttributeKeyRecipient = "recipient" | ||
AttributeKeyTarget = "target" | ||
AttributeKeyMemo = "memo" | ||
) |
This file contains 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 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
Oops, something went wrong.