From 723471f3a9369ad76b0fe1eb43246652b9f624be Mon Sep 17 00:00:00 2001 From: xinran chen Date: Sun, 2 Jul 2023 16:53:46 +0800 Subject: [PATCH] subevent chan --- benchmark/bench_transfer.go | 2 +- core/result/event.go | 4 ++++ example/client/callchain/callchain.go | 5 ++++- example/client/client.go | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/benchmark/bench_transfer.go b/benchmark/bench_transfer.go index 8482eb32..a0fb2974 100644 --- a/benchmark/bench_transfer.go +++ b/benchmark/bench_transfer.go @@ -28,7 +28,7 @@ func main() { } go caculateTPS() - go SubEvent() + go SubEvent(nil) start := time.Now() diff --git a/core/result/event.go b/core/result/event.go index 93e5c3e0..81ba26bb 100644 --- a/core/result/event.go +++ b/core/result/event.go @@ -39,6 +39,10 @@ func (e *Event) Decode(data []byte) error { return json.Unmarshal(data[ResultTypeBytesLen:], e) } +func (e *Event) DecodeJsonValue(v any) error { + return json.Unmarshal(e.Value, v) +} + func (e *Event) Type() ResultType { return EventType } diff --git a/example/client/callchain/callchain.go b/example/client/callchain/callchain.go index 7ad8223d..9df948c1 100644 --- a/example/client/callchain/callchain.go +++ b/example/client/callchain/callchain.go @@ -115,7 +115,7 @@ func CallChainByWriting(reqType int, privkey PrivKey, pubkey PubKey, ecall *WrCa } } -func SubEvent() { +func SubEvent(ch chan Result) { u := url.URL{Scheme: "ws", Host: "localhost:8999", Path: SubResultsPath} c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) if err != nil { @@ -137,5 +137,8 @@ func SubEvent() { case ErrorType: logrus.Error(result.(*Error).Error()) } + if ch != nil { + ch <- result + } } } diff --git a/example/client/client.go b/example/client/client.go index d987ae54..7f002363 100644 --- a/example/client/client.go +++ b/example/client/client.go @@ -20,7 +20,7 @@ func main() { panic("generate To Address key error: " + err.Error()) } - go SubEvent() + go SubEvent(nil) logrus.Info("--- send Creating Account ---") CreateAccount(Http, privkey, pubkey, 500)