Skip to content
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 --from flag at get-oracle-key #73

Merged
merged 6 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ const (
FlagOracleCommissionRate = "oracle-commission-rate"
FlagOracleCommissionMaxRate = "oracle-commission-max-rate"
FlagOracleCommissionMaxChangeRate = "oracle-commission-max-change-rate"

FlagFromOracleRegistrationOrUpgrade = "from"
)
41 changes: 35 additions & 6 deletions cmd/oracled/cmd/get_oracle_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import (
"context"
"fmt"

"github.com/medibloc/panacea-oracle/client/flags"
"github.com/medibloc/panacea-oracle/key"
"github.com/medibloc/panacea-oracle/service"
"github.com/spf13/cobra"
)

const (
fromRegistration = "registration"
fromUpgrade = "upgrade"
)

func getOracleKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get-oracle-key",
Expand All @@ -28,18 +34,41 @@ func getOracleKeyCmd() *cobra.Command {

uniqueID := svc.EnclaveInfo().UniqueIDHex()
oracleAddress := svc.OracleAcc().GetAddress()
oracleRegistration, err := svc.QueryClient().GetOracleRegistration(ctx, uniqueID, oracleAddress)

from, err := cmd.Flags().GetString(flags.FlagFromOracleRegistrationOrUpgrade)
if err != nil {
return fmt.Errorf("failed to get oracle registration: %w", err)
return err
}

if len(oracleRegistration.EncryptedOraclePrivKey) == 0 {
return fmt.Errorf("the encrypted oracle private key has not set yet. please try again later")
}
switch from {
case fromRegistration:
oracleRegistration, err := svc.QueryClient().GetOracleRegistration(ctx, uniqueID, oracleAddress)
if err != nil {
return fmt.Errorf("failed to get oracle registration: %w", err)
}

return key.RetrieveAndStoreOraclePrivKey(ctx, svc, oracleRegistration.EncryptedOraclePrivKey)
if len(oracleRegistration.EncryptedOraclePrivKey) == 0 {
return fmt.Errorf("the encrypted oracle private key has not set yet. please try again later")
}
return key.RetrieveAndStoreOraclePrivKey(ctx, svc, oracleRegistration.EncryptedOraclePrivKey)

case fromUpgrade:
oracleUpgrade, err := svc.QueryClient().GetOracleUpgrade(ctx, uniqueID, oracleAddress)
if err != nil {
return fmt.Errorf("failed to get oracle upgrade: %w", err)
}
if len(oracleUpgrade.EncryptedOraclePrivKey) == 0 {
return fmt.Errorf("the encrypted oracle private key has not set yet. please try again later")
}
return key.RetrieveAndStoreOraclePrivKey(ctx, svc, oracleUpgrade.EncryptedOraclePrivKey)

default:
return fmt.Errorf("invalid --from flag input. please put \"registration\" or \"upgrade\"")
}
},
}

cmd.Flags().String(flags.FlagFromOracleRegistrationOrUpgrade, fromUpgrade, "where to get the key from")

return cmd
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/ipfs/go-ipfs-api v0.3.0
github.com/lestrrat-go/jwx/v2 v2.0.8
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230105013527-4f854a29b04d
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230112003445-72ed7747a21b
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.13.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,8 @@ github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88J
github.com/mbilski/exhaustivestruct v1.2.0/go.mod h1:OeTBVxQWoEmB2J2JCHmXWPJ0aksxSUOUy+nvtVEfzXc=
github.com/medibloc/cosmos-sdk v0.45.9-panacea.1 h1:JTprXN6z/+6UjkjQU4OfDz7z+sUpzev1s9DywmWA2Sk=
github.com/medibloc/cosmos-sdk v0.45.9-panacea.1/go.mod h1:Z5M4TX7PsHNHlF/1XanI2DIpORQ+Q/st7oaeufEjnvU=
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230104081432-e5cc1c5514cd h1:cljJCsJwn8rbk2NZW2klZ9rId5d3Bv/h6uEx0H/uhMI=
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230104081432-e5cc1c5514cd/go.mod h1:YCYoLlbegqIP8fbrpvrvkK5LsQojDxukneKczbZ7hic=
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230105013527-4f854a29b04d h1:s2+xmKkrJ7k9fKz5wJkpnbeCiuh7MVg5LFaFo4UoxE0=
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230105013527-4f854a29b04d/go.mod h1:YCYoLlbegqIP8fbrpvrvkK5LsQojDxukneKczbZ7hic=
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230112003445-72ed7747a21b h1:Xb4AM4Rs3tx1fUoMUNHqQ0xCbRZyo/eK0FwxzM+j4z4=
github.com/medibloc/panacea-core/v2 v2.0.6-0.20230112003445-72ed7747a21b/go.mod h1:YCYoLlbegqIP8fbrpvrvkK5LsQojDxukneKczbZ7hic=
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg=
github.com/mgechev/revive v1.2.1/go.mod h1:+Ro3wqY4vakcYNtkBWdZC7dBg1xSB6sp054wWwmeFm0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
Expand Down