-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add CLI register-oracle
#17
Conversation
cmd/oracled/cmd/register_oracle.go
Outdated
// subscribe approval of oracle registration and handle it | ||
client, err := rpchttp.New(conf.Panacea.RPCAddr, "/websocket") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := client.Start(); err != nil { | ||
return err | ||
} | ||
defer func() { | ||
_ = client.Stop() | ||
}() | ||
|
||
event := oracleevent.NewApproveOracleRegistrationEvent() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
defer cancel() | ||
|
||
txs, err := client.Subscribe(ctx, "", event.GetEventQuery()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
errChan := make(chan error, 1) | ||
|
||
for tx := range txs { | ||
errChan <- event.EventHandler(tx) | ||
} | ||
|
||
err = <-errChan | ||
if err != nil { | ||
log.Infof("Error occurs while getting shared oracle private key. Please retrieve it via get-oracle-key cmd: %v", err) | ||
return err | ||
} else { | ||
log.Infof("oracle private key is successfully shared. You can start oracle now!") | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If MsgRegisterOracle
succeed, subscribe MsgApproveOracleRegistration
and handle it in a synchronous way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍 lgtm!
But I have one question here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good
cmd/oracled/cmd/register_oracle.go
Outdated
return err | ||
} | ||
defer func() { | ||
_ = client.Stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about printing a log when error occurs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add it. Thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I left a one question.
} | ||
|
||
func NewApproveOracleRegistrationEvent(s event.Reactor) ApproveOracleRegistrationEvent { | ||
return ApproveOracleRegistrationEvent{s} | ||
func NewApproveOracleRegistrationEvent() ApproveOracleRegistrationEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question. Why remove the reactor for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this PR, I don't want to create a service for reactor, which has many things in it.
This ApproveOracleRegistrationEvent
don't need all that resources in service.
I've been thinking about how to make this ApproveOracleRegistrationEvent
better. If you have any idea, please feel free to leave your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand it! I'll also thinking about how to make it better. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
close #2