crosschain

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess int = 0
	StatusFailed  int = 1
)

Variables

View Source
var (
	//contract address, 9999
	//todo: transfer remain BCH to this address before working
	CCContractAddress [20]byte = [20]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x27, 0x09}
	/*------selector------*/
	/*interface CC {
	    function transferBCHToMainnet(bytes utxo) external;
	    function burnBCH(bytes utxo) external;

	    event TransferToMainnet(bytes32 indexed mainnetTxId, bytes4 indexed vOutIndex, address indexed from, uint256 value);
	    event Burn(bytes32 indexed mainnetTxId, bytes4 indexed vOutIndex, uint256 value);
	}*/
	SelectorTransferBchToMainnet [4]byte = [4]byte{0xa0, 0x4f, 0x3b, 0x01}
	SelectorBurnBCH              [4]byte = [4]byte{0x18, 0x92, 0xa8, 0xb3}

	HashOfEventTransferToBch [32]byte = common.HexToHash("0x4a9f09be1e2df144675144ec10cb5fe6c05504a84262275b62028189c1d410c1")
	HashOfEventBurn          [32]byte = common.HexToHash("0xeae299b236fc8161793d044c8260b3dc7f8c20b5b3b577eb7f075e4a9c3bf48d")

	GasOfCCOp uint64 = 400_000

	InvalidCallData   = errors.New("invalid call data")
	InvalidSelector   = errors.New("invalid selector")
	BchAmountNotMatch = errors.New("value not match bch amount in utxo")
	BalanceNotEnough  = errors.New("balance is not enough")
	BurnToMuch        = errors.New("burn more bch than reality")

	SlotCCInfo          string = strings.Repeat(string([]byte{0}), 32)
	SlotBCHAlreadyBurnt string = strings.Repeat(string([]byte{0}), 31) + string([]byte{1})
)
View Source
var ABI = ethutils.MustParseABI(`
[
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "bytes32",
				"name": "mainnetTxId",
				"type": "bytes32"
			},
			{
				"indexed": true,
				"internalType": "bytes4",
				"name": "vOutIndex",
				"type": "bytes4"
			},
			{
				"indexed": false,
				"internalType": "uint256",
				"name": "value",
				"type": "uint256"
			}
		],
		"name": "Burn",
		"type": "event"
	},
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "bytes32",
				"name": "mainnetTxId",
				"type": "bytes32"
			},
			{
				"indexed": true,
				"internalType": "bytes4",
				"name": "vOutIndex",
				"type": "bytes4"
			},
			{
				"indexed": true,
				"internalType": "address",
				"name": "from",
				"type": "address"
			},
			{
				"indexed": false,
				"internalType": "uint256",
				"name": "value",
				"type": "uint256"
			}
		],
		"name": "TransferToMainnet",
		"type": "event"
	},
	{
		"inputs": [
			{
				"internalType": "bytes",
				"name": "utxo",
				"type": "bytes"
			}
		],
		"name": "burnBCH",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "bytes",
				"name": "utxo",
				"type": "bytes"
			}
		],
		"name": "transferBCHToMainnet",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	}
]
`)

Functions

func LoadBchMainnetBurnt

func LoadBchMainnetBurnt(ctx *mevmtypes.Context) *uint256.Int

func LoadCCEpoch

func LoadCCEpoch(ctx *mevmtypes.Context, epochNum int64) (epoch types.CCEpoch, ok bool)

func LoadCCInfo

func LoadCCInfo(ctx *mevmtypes.Context) (info types.CCInfo)

func LoadUTXO

func LoadUTXO(ctx *mevmtypes.Context, utxo [36]byte) *uint256.Int

func PackBurnBCH

func PackBurnBCH(utxo [36]byte) []byte

func PackTransferBCHToMainnet

func PackTransferBCHToMainnet(utxo [36]byte) []byte

func SaveBchMainnetBurnt

func SaveBchMainnetBurnt(ctx *mevmtypes.Context, amount *uint256.Int)

func SaveCCEpoch

func SaveCCEpoch(ctx *mevmtypes.Context, epochNum int64, epoch *types.CCEpoch)

func SaveCCInfo

func SaveCCInfo(ctx *mevmtypes.Context, info types.CCInfo)

func SaveUTXO

func SaveUTXO(ctx *mevmtypes.Context, utxo [36]byte, amount *uint256.Int)

func SwitchCCEpoch

func SwitchCCEpoch(ctx *mevmtypes.Context, epoch *types.CCEpoch)

func UpdateBchBurnt

func UpdateBchBurnt(ctx *mevmtypes.Context, amount *uint256.Int) error

Types

type CcContractExecutor

type CcContractExecutor struct {
	// contains filtered or unexported fields
}

func NewCcContractExecutor

func NewCcContractExecutor(logger log.Logger) *CcContractExecutor

func (*CcContractExecutor) Execute

func (s *CcContractExecutor) Execute(ctx *mevmtypes.Context, currBlock *mevmtypes.BlockInfo, tx *mevmtypes.TxToRun) (status int, logs []mevmtypes.EvmLog, gasUsed uint64, outData []byte)

func (*CcContractExecutor) Init

func (_ *CcContractExecutor) Init(ctx *mevmtypes.Context)

func (*CcContractExecutor) IsSystemContract

func (_ *CcContractExecutor) IsSystemContract(addr common.Address) bool

func (*CcContractExecutor) RequiredGas

func (_ *CcContractExecutor) RequiredGas(_ []byte) uint64

this functions is called when other contract calls

func (*CcContractExecutor) Run

func (_ *CcContractExecutor) Run(_ []byte) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL