Skip to content

Commit

Permalink
Merge branch 'dev' into zhangkai/fix-iaviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
giskook authored May 12, 2023
2 parents a8351c8 + ec80d21 commit 7f4f05b
Show file tree
Hide file tree
Showing 59 changed files with 4,756 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ func NewOKExChainApp(
wasmModule := wasm.NewAppModule(*app.marshal, &app.WasmKeeper)
app.WasmPermissionKeeper = wasmModule.GetPermissionKeeper()
app.VMBridgeKeeper = vmbridge.NewKeeper(app.marshal, app.Logger(), app.EvmKeeper, app.WasmPermissionKeeper, app.AccountKeeper, app.BankKeeper)

app.EvmKeeper.SetCallToCM(vmbridge.PrecompileHooks(app.VMBridgeKeeper))
// Set EVM hooks
app.EvmKeeper.SetHooks(
evm.NewMultiEvmHooks(
Expand Down
38 changes: 38 additions & 0 deletions dev/vmbridge/counter/evmContract/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "./lib/JsonWriter.sol";
import "./lib/StringHelper.sol";

contract Counter is StringHelper {
uint128 public count;

using JsonWriter for JsonWriter.Json;

event __OKCCallToWasm(string wasmAddr, uint256 value, string wasmMsg);

function addCounterForWasm(
string memory _wasmContractAddress,
string memory delta
) public {
//Assemble JSON data
JsonWriter.Json memory _wasmMsg;

_wasmMsg = _wasmMsg.writeStartObject();
_wasmMsg = _wasmMsg.writeStartObject("add");
_wasmMsg = _wasmMsg.writeStringProperty("delta", delta);
_wasmMsg = _wasmMsg.writeEndObject();
_wasmMsg = _wasmMsg.writeEndObject();

//The specific event “__OKCCallToWasm” can trigger a wasm transaction
emit __OKCCallToWasm(
_wasmContractAddress, //wasm contract address(to)
0, //The native token you want to send
stringToHexString(_wasmMsg.value) //JSON => HexString
);
}

function add(uint128 delta) public {
count = count + delta;
}
}
103 changes: 103 additions & 0 deletions dev/vmbridge/counter/evmContract/evmContract.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "wasmAddr",
"type": "string"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "wasmMsg",
"type": "string"
}
],
"name": "__OKCCallToWasm",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint128",
"name": "delta",
"type": "uint128"
}
],
"name": "add",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint128",
"name": "delta",
"type": "uint128"
}
],
"name": "sub",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_wasmContractAddress",
"type": "string"
},
{
"internalType": "string",
"name": "delta",
"type": "string"
}
],
"name": "addCounterForWasm",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "count",
"outputs": [
{
"internalType": "uint128",
"name": "",
"type": "uint128"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_str",
"type": "string"
}
],
"name": "stringToHexString",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "pure",
"type": "function"
}
]
1 change: 1 addition & 0 deletions dev/vmbridge/counter/evmContract/evmContract.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b50611228806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c806304da9aff1461005157806306661abd1461006d57806343114db81461008b578063ac9a8ae1146100a7575b600080fd5b61006b60048036038101906100669190610a22565b6100d7565b005b6100756101e3565b6040516100829190610ac5565b60405180910390f35b6100a560048036038101906100a09190610b0c565b610203565b005b6100c160048036038101906100bc9190610b39565b610265565b6040516100ce9190610c01565b60405180910390f35b6100df6108ae565b6100e8816104b0565b90506101326040518060400160405280600381526020017f6164640000000000000000000000000000000000000000000000000000000000815250826104e990919063ffffffff16565b905061017e6040518060400160405280600581526020017f64656c746100000000000000000000000000000000000000000000000000000081525083836105249092919063ffffffff16565b9050610189816105e3565b9050610194816105e3565b90507fcca73dc0c9131f3d7540642f5b7bc76eceaedddf94108f54b7a7c9e594d967bf8360006101c78460200151610265565b6040516101d693929190610c72565b60405180910390a1505050565b60008054906101000a90046fffffffffffffffffffffffffffffffff1681565b8060008054906101000a90046fffffffffffffffffffffffffffffffff1661022b9190610ce6565b6000806101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555050565b606060008260405160200161027a9190610d66565b604051602081830303815290604052905060006040518060400160405280601081526020017f303132333435363738396162636465660000000000000000000000000000000081525090506000600283516102d59190610d7d565b67ffffffffffffffff8111156102ee576102ed6108f7565b5b6040519080825280601f01601f1916602001820160405280156103205781602001600182028036833780820191505090505b50905060005b83518110156104a45782600485838151811061034557610344610dbf565b5b602001015160f81c60f81b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916901c60f81c60ff168151811061038b5761038a610dbf565b5b602001015160f81c60f81b826002836103a49190610d7d565b60006103b09190610dee565b815181106103c1576103c0610dbf565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535082600f60f81b85838151811061040957610408610dbf565b5b602001015160f81c60f81b1660f81c60ff168151811061042c5761042b610dbf565b5b602001015160f81c60f81b826002836104459190610d7d565b60016104519190610dee565b8151811061046257610461610dbf565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061049c90610e22565b915050610326565b50809350505050919050565b6104b86108ae565b6104e2827f7b0000000000000000000000000000000000000000000000000000000000000061061c565b9050919050565b6104f16108ae565b61051c83837f7b00000000000000000000000000000000000000000000000000000000000000610704565b905092915050565b61052c6108ae565b60008290506000856000015112156105955784602001517f2c0000000000000000000000000000000000000000000000000000000000000085836040516020016105799493929190610f4f565b60405160208183030381529060405285602001819052506105c6565b846020015184826040516020016105ae93929190610fb2565b60405160208183030381529060405285602001819052505b6105cf856107f1565b856000018181525050849150509392505050565b6105eb6108ae565b610615827f7d00000000000000000000000000000000000000000000000000000000000000610806565b9050919050565b6106246108ae565b6000836000015112156106865782602001517f2c000000000000000000000000000000000000000000000000000000000000008360405160200161066a93929190611004565b60405160208183030381529060405283602001819052506106b5565b82602001518260405160200161069d92919061103d565b60405160208183030381529060405283602001819052505b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360000181815116915081815250508260000180518091906106f79061106f565b8152505082905092915050565b61070c6108ae565b6000846000015112156107705783602001517f2c0000000000000000000000000000000000000000000000000000000000000084846040516020016107549493929190611103565b60405160208183030381529060405284602001819052506107a1565b836020015183836040516020016107899392919061115f565b60405160208183030381529060405284602001819052505b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8460000181815116915081815250508360000180518091906107e39061106f565b815250508390509392505050565b600060ff6001901b8260000151179050919050565b61080e6108ae565b82602001518260405160200161082592919061103d565b6040516020818303038152906040528360200181905250610845836107f1565b83600001818152505060006108598461087e565b1461087557826000018051809190610870906111aa565b815250505b82905092915050565b60007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260000151169050919050565b604051806040016040528060008152602001606081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61092f826108e6565b810181811067ffffffffffffffff8211171561094e5761094d6108f7565b5b80604052505050565b60006109616108c8565b905061096d8282610926565b919050565b600067ffffffffffffffff82111561098d5761098c6108f7565b5b610996826108e6565b9050602081019050919050565b82818337600083830152505050565b60006109c56109c084610972565b610957565b9050828152602081018484840111156109e1576109e06108e1565b5b6109ec8482856109a3565b509392505050565b600082601f830112610a0957610a086108dc565b5b8135610a198482602086016109b2565b91505092915050565b60008060408385031215610a3957610a386108d2565b5b600083013567ffffffffffffffff811115610a5757610a566108d7565b5b610a63858286016109f4565b925050602083013567ffffffffffffffff811115610a8457610a836108d7565b5b610a90858286016109f4565b9150509250929050565b60006fffffffffffffffffffffffffffffffff82169050919050565b610abf81610a9a565b82525050565b6000602082019050610ada6000830184610ab6565b92915050565b610ae981610a9a565b8114610af457600080fd5b50565b600081359050610b0681610ae0565b92915050565b600060208284031215610b2257610b216108d2565b5b6000610b3084828501610af7565b91505092915050565b600060208284031215610b4f57610b4e6108d2565b5b600082013567ffffffffffffffff811115610b6d57610b6c6108d7565b5b610b79848285016109f4565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610bbc578082015181840152602081019050610ba1565b60008484015250505050565b6000610bd382610b82565b610bdd8185610b8d565b9350610bed818560208601610b9e565b610bf6816108e6565b840191505092915050565b60006020820190508181036000830152610c1b8184610bc8565b905092915050565b6000819050919050565b6000819050919050565b6000819050919050565b6000610c5c610c57610c5284610c23565b610c37565b610c2d565b9050919050565b610c6c81610c41565b82525050565b60006060820190508181036000830152610c8c8186610bc8565b9050610c9b6020830185610c63565b8181036040830152610cad8184610bc8565b9050949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610cf182610a9a565b9150610cfc83610a9a565b925082820190506fffffffffffffffffffffffffffffffff811115610d2457610d23610cb7565b5b92915050565b600081905092915050565b6000610d4082610b82565b610d4a8185610d2a565b9350610d5a818560208601610b9e565b80840191505092915050565b6000610d728284610d35565b915081905092915050565b6000610d8882610c2d565b9150610d9383610c2d565b9250828202610da181610c2d565b91508282048414831517610db857610db7610cb7565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000610df982610c2d565b9150610e0483610c2d565b9250828201905080821115610e1c57610e1b610cb7565b5b92915050565b6000610e2d82610c2d565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610e5f57610e5e610cb7565b5b600182019050919050565b60007fff0000000000000000000000000000000000000000000000000000000000000082169050919050565b6000819050919050565b610eb1610eac82610e6a565b610e96565b82525050565b7f2200000000000000000000000000000000000000000000000000000000000000600082015250565b6000610eed600183610d2a565b9150610ef882610eb7565b600182019050919050565b7f223a202200000000000000000000000000000000000000000000000000000000600082015250565b6000610f39600483610d2a565b9150610f4482610f03565b600482019050919050565b6000610f5b8287610d35565b9150610f678286610ea0565b600182019150610f7682610ee0565b9150610f828285610d35565b9150610f8d82610f2c565b9150610f998284610d35565b9150610fa482610ee0565b915081905095945050505050565b6000610fbe8286610d35565b9150610fc982610ee0565b9150610fd58285610d35565b9150610fe082610f2c565b9150610fec8284610d35565b9150610ff782610ee0565b9150819050949350505050565b60006110108286610d35565b915061101c8285610ea0565b60018201915061102c8284610ea0565b600182019150819050949350505050565b60006110498285610d35565b91506110558284610ea0565b6001820191508190509392505050565b6000819050919050565b600061107a82611065565b91507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036110ac576110ab610cb7565b5b600182019050919050565b7f223a200000000000000000000000000000000000000000000000000000000000600082015250565b60006110ed600383610d2a565b91506110f8826110b7565b600382019050919050565b600061110f8287610d35565b915061111b8286610ea0565b60018201915061112a82610ee0565b91506111368285610d35565b9150611141826110e0565b915061114d8284610ea0565b60018201915081905095945050505050565b600061116b8286610d35565b915061117682610ee0565b91506111828285610d35565b915061118d826110e0565b91506111998284610ea0565b600182019150819050949350505050565b60006111b582611065565b91507f800000000000000000000000000000000000000000000000000000000000000082036111e7576111e6610cb7565b5b60018203905091905056fea2646970667358221220205cb62560086b143d90310fa736f324a0e234d3d9197e162be604fdb5138eb164736f6c63430008110033
21 changes: 21 additions & 0 deletions dev/vmbridge/counter/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module vmbridge

go 1.17

require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/go-ethereum v1.11.5 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
32 changes: 32 additions & 0 deletions dev/vmbridge/counter/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI=
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/ethereum/go-ethereum v1.11.5 h1:3M1uan+LAUvdn+7wCEFrcMM4LJTeuxDrPTg/f31a5QQ=
github.com/ethereum/go-ethereum v1.11.5/go.mod h1:it7x0DWnTDMfVFdXcU6Ti4KEFQynLHVRarcSlPr0HBo=
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4=
github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI=
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
Loading

0 comments on commit 7f4f05b

Please sign in to comment.