Last active
February 21, 2022 11:15
-
-
Save obscuren/fe446966908bab446b7b to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"log" | |
"strings" | |
"github.com/ethereum/go-ethereum/accounts/abi" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/xeth" | |
) | |
// the definition | |
const definition = ` | |
[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBar","outputs":[{"name":"","type":"bool"}],"type":"function"}] | |
` | |
// the contract | |
const contract = ` | |
contract Foo { | |
mapping(address => bool) public isBar; | |
} | |
` | |
func main() { | |
abi, err := abi.JSON(strings.NewReader(definition)) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
out, err := abi.Pack("isBar", common.HexToAddress("01")) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
xeth := xeth.New(ethereum_instance, nil) | |
xeth.Call(from, to, "0", "1000000000", "0", common.Bytes2Hex(out)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi obscuren,
I am trying to implement your example. Here is the setup for my app. I need to implement node authorization to restrict any node connecting to my node if node is not in registered in my local node contract.
I have compiled contract which should contain nodes in online compiler and added it code to genesis.json file so ethereum will deploy contract by default without submitting it through console. Also I use abi definition from the compiler as well. Also, I updated code in abi package to use inputs instead input.
Here is the code which submits new node to the contract (I tried xeth.Call and xeth.Transact with miner.start())
Here is the code which tries to read contract when new node tries to connect to this node
The issue is that response from hexStr, _, _ := self.Call(fromStr, "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d", valueStr, gasStr, gasPriceStr, common.Bytes2Hex(out)) is always false
and response from
exStr2, _, _ := self.Call(fromStr, "0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d", valueStr, gasStr, gasPriceStr, common.Bytes2Hex(out2))
is empty.
0x3282791d6fd713f1e94f4bfd565eaa78b3a0599d is the contract address which is hardcoded is genesis.json file
Could you help me figure out the issue?