diff --git a/sui/scripts/deploy.sh b/sui/scripts/deploy.sh index 15d4e1977b..c5e0ebe0af 100755 --- a/sui/scripts/deploy.sh +++ b/sui/scripts/deploy.sh @@ -9,6 +9,8 @@ sui client publish --gas-budget 10000 | tee publish.log wa="`grep "The newly published package" publish.log | sed -e 's/^.*: //'`" sed -i -e "s/wormhole = .*/wormhole = \"$wa\"/" Move.toml state="`grep "Move Object" publish.log | sed -e 's/^.*(\(.*\)\[.*$/\1/'`" +owner="`grep '^Owner: Account Address' publish.log | sed -e 's/^.* ( \(.*\) )/\1/'`" echo "WORM_PACKAGE=\"$wa\"" > ../env.sh echo "WORM_STATE=\"$state\"" >> ../env.sh +echo "WORM_OWNER=\"$owner\"" >> ../env.sh diff --git a/sui/tests/go.mod b/sui/tests/go.mod index e5009e6ccf..d30aab4ccb 100644 --- a/sui/tests/go.mod +++ b/sui/tests/go.mod @@ -2,4 +2,4 @@ module watcher go 1.17 -require github.com/gorilla/websocket v1.5.0 // indirect +require golang.org/x/net v0.1.0 // indirect diff --git a/sui/tests/go.sum b/sui/tests/go.sum index e5a03d4dc9..4deb3db8ae 100644 --- a/sui/tests/go.sum +++ b/sui/tests/go.sum @@ -1,2 +1,2 @@ -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= diff --git a/sui/tests/watcher.go b/sui/tests/watcher.go index b841e3bfc9..76859ccef2 100644 --- a/sui/tests/watcher.go +++ b/sui/tests/watcher.go @@ -1,85 +1,35 @@ -// Copyright 2015 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build ignore -// +build ignore - -// go get github.com/gorilla/websocket - package main import ( - "flag" + "fmt" + "golang.org/x/net/websocket" "log" - "net/url" - "os" - "os/signal" "time" - - "github.com/gorilla/websocket" + "os" ) -var addr = flag.String("addr", "localhost:5001", "http service address") - func main() { - flag.Parse() - log.SetFlags(0) - - interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, os.Interrupt) - - u := url.URL{Scheme: "ws", Host: *addr, Path: "/sui_subscribeEvent"} - log.Printf("connecting to %s", u.String()) - - c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) + origin := "http://localhost/" + url := "ws://localhost:9001" + ws, err := websocket.Dial(url, "", origin) if err != nil { - log.Fatal("dial:", err) + log.Fatal(err) } - defer c.Close() - done := make(chan struct{}) - - go func() { - defer close(done) - for { - _, message, err := c.ReadMessage() - if err != nil { - log.Println("read:", err) - return - } - log.Printf("recv: %s", message) - } - }() - - ticker := time.NewTicker(time.Second) - defer ticker.Stop() + s := fmt.Sprintf(`{"jsonrpc":"2.0", "id": 1, "method": "sui_subscribeEvent", "params": [{"SenderAddress": "%s"}]}`, os.Getenv("WORM_OWNER")) + fmt.Printf("Sending: %s.\n", s) + if _, err := ws.Write([]byte(s)); err != nil { + log.Fatal(err) + } for { - select { - case <-done: - return - case t := <-ticker.C: - err := c.WriteMessage(websocket.TextMessage, []byte(t.String())) - if err != nil { - log.Println("write:", err) - return - } - case <-interrupt: - log.Println("interrupt") - - // Cleanly close the connection by sending a close message and then - // waiting (with timeout) for the server to close the connection. - err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) - if err != nil { - log.Println("write close:", err) - return - } - select { - case <-done: - case <-time.After(time.Second): - } - return + var msg = make([]byte, 512) + var n int + ws.SetReadDeadline(time.Now().Local().Add(1_000_000_000)); + if n, err = ws.Read(msg); err != nil { + fmt.Printf("err"); + } else { + fmt.Printf("Received: %s.\n", msg[:n]) } } } diff --git a/sui/tests/ws.py b/sui/tests/ws.py index 62f1bd63df..33e9a6ccba 100644 --- a/sui/tests/ws.py +++ b/sui/tests/ws.py @@ -2,9 +2,71 @@ import _thread import time import rel +import os +import pprint +import json +import base64 + +# https://github.com/MystenLabs/sui/pull/5113 + +# { +# "jsonrpc": "2.0", +# "method": "sui_subscribeEvent", +# "params": { +# "subscription": 1805876586195140, +# "result": { +# "timestamp": 1666704112752, +# "txDigest": "ckB13AaG+OHrO0Ha3I8IK3ERanYHmHAI0jSXnqk9R+I=", +# "event": { +# "moveEvent": { +# "packageId": "0xbd99019f3c8f9d08b5498fedcc97e1c24cddff88", +# "transactionModule": "wormhole", +# "sender": "0xdc2f7334400a353c6a9303235b578477202809c6", +# "type": "0xbd99019f3c8f9d08b5498fedcc97e1c24cddff88::state::WormholeMessage", +# "fields": { +# "consistency_level": 0, +# "nonce": 400, +# "payload": "Ag==", +# "sender": "0xdc2f7334400a353c6a9303235b578477202809c6", +# "sequence": 19, +# "timestamp": 0 +# }, +# "bcs": "3C9zNEAKNTxqkwMjW1eEdyAoCcYTAAAAAAAAAJABAAAAAAAAAQIAAAAAAAAAAAA=" +# } +# } +# } +# } +# } + +# curl -s -X POST -d '{"jsonrpc":"2.0", "id": 1, "method": "sui_getEventsByTransaction", "params": ["KgsiF8pCF61N02zX2oMFYLWQdrbxkOD1ypBxND752No=", 2]}' -H 'Content-Type: application/json' http://127.0.0.1:9000 | jq + +# { +# "jsonrpc": "2.0", +# "result": [ +# { +# "timestamp": 1666704112752, +# "txDigest": "ckB13AaG+OHrO0Ha3I8IK3ERanYHmHAI0jSXnqk9R+I=", +# "event": { +# "moveEvent": { +# "packageId": "0xbd99019f3c8f9d08b5498fedcc97e1c24cddff88", +# "transactionModule": "wormhole", +# "sender": "0xdc2f7334400a353c6a9303235b578477202809c6", +# "type": "0xbd99019f3c8f9d08b5498fedcc97e1c24cddff88::state::WormholeMessage", +# "bcs": "3C9zNEAKNTxqkwMjW1eEdyAoCcYTAAAAAAAAAJABAAAAAAAAAQIAAAAAAAAAAAA=" +# } +# } +# } +# ], +# "id": 1 +# } def on_message(ws, message): - print(message) + v = json.loads(message) + if "params" in v: + tx = v["params"]["result"]["txDigest"] + tx = len(base64.standard_b64decode(tx)) + print(tx.hex()) + print(json.dumps(v, indent=4)) def on_error(ws, error): print(error) @@ -14,10 +76,9 @@ def on_close(ws, close_status_code, close_msg): def on_open(ws): print("Opened connection") - ws.send("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"sui_subscribeEvent\", \"params\": [{\"SenderAddress\": \"0xf4e306649ca37370e61c27b1fc684dae62234b78\"}]}") + ws.send("{\"jsonrpc\":\"2.0\", \"id\": 1, \"method\": \"sui_subscribeEvent\", \"params\": [{\"SenderAddress\": \"" + os.getenv("WORM_OWNER") + "\"}]}") if __name__ == "__main__": - websocket.enableTrace(True) ws = websocket.WebSocketApp("ws://localhost:9001", on_open=on_open, on_message=on_message, diff --git a/sui/wormhole/Move.toml b/sui/wormhole/Move.toml index 6800822342..116b28eec5 100644 --- a/sui/wormhole/Move.toml +++ b/sui/wormhole/Move.toml @@ -6,4 +6,4 @@ version = "0.0.1" Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework", rev = "devnet" } [addresses] -wormhole = "0xbbd7f613afc47d3f8b991208f6444107fec1a52d" +wormhole = "0xbd99019f3c8f9d08b5498fedcc97e1c24cddff88"