Skip to content

Instantly share code, notes, and snippets.

@obscuren
Created February 9, 2017 13:40
Show Gist options
  • Save obscuren/1d6b2ed8876c271a96910e848b0fc027 to your computer and use it in GitHub Desktop.
Save obscuren/1d6b2ed8876c271a96910e848b0fc027 to your computer and use it in GitHub Desktop.
diff --git a/eth/backend.go b/eth/backend.go
index af120cb..80accdd 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
@@ -352,10 +353,25 @@ func (s *Ethereum) APIs() []rpc.API {
Version: "1.0",
Service: s.netRPCService,
Public: true,
+ }, {
+ Namespace: "shh",
+ Version: "0.1",
+ Service: PublicWhisperAPI{},
+ Public: true,
},
}...)
}
+type PublicWhisperAPI struct{}
+
+func (PublicWhisperAPI) HelloWorld(data hexutil.Bytes) (hexutil.Bytes, error) {
+ return append(data, data...), nil
+}
+
+func (PublicWhisperAPI) HelloWorld2(data hexutil.Bytes) (hexutil.Bytes, error) {
+ return nil, fmt.Errorf("hello wold error")
+}
+
func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb)
}
diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go
index edbe45f..c5f5998 100644
--- a/internal/web3ext/web3ext.go
+++ b/internal/web3ext/web3ext.go
@@ -470,14 +470,25 @@ web3._extend({
const Shh_JS = `
web3._extend({
property: 'shh',
- methods: [],
+ methods: [
+ new web3._extend.Method({
+ name:"helloWorld",
+ call: "shh_helloWorld",
+ params: 1,
+ }),
+ new web3._extend.Method({
+ name:"helloWorld2",
+ call: "shh_helloWorld2",
+ params: 1,
+ }),
+ ],
properties:
[
new web3._extend.Property({
name: 'version',
getter: 'shh_version',
outputFormatter: web3._extend.utils.toDecimal
- })
+ }),
]
});
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment