From ec6742ddd4ee1df170705999db0f5bb9665f724d Mon Sep 17 00:00:00 2001 From: audtlr24 Date: Thu, 12 Jan 2023 16:07:05 +0900 Subject: [PATCH 1/5] feat: improve get oracle key --- client/flags/flags.go | 2 ++ cmd/oracled/cmd/get_oracle_key.go | 33 ++++++++++++++++++++++++++----- go.sum | 4 ++-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index 7ed45bd..3d26f38 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -10,4 +10,6 @@ const ( FlagOracleCommissionRate = "oracle-commission-rate" FlagOracleCommissionMaxRate = "oracle-commission-max-rate" FlagOracleCommissionMaxChangeRate = "oracle-commission-max-change-rate" + + FlagFromOracleRegistrationOrUpgrade = "from" ) diff --git a/cmd/oracled/cmd/get_oracle_key.go b/cmd/oracled/cmd/get_oracle_key.go index bbb65d1..ae082b3 100644 --- a/cmd/oracled/cmd/get_oracle_key.go +++ b/cmd/oracled/cmd/get_oracle_key.go @@ -4,6 +4,7 @@ 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" @@ -28,18 +29,40 @@ 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") + if from == "registration" { + oracleRegistration, err := svc.QueryClient().GetOracleRegistration(ctx, uniqueID, oracleAddress) + if err != nil { + return fmt.Errorf("failed to get oracle registration: %w", err) + } + + 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) + + } else if from == "upgrade" { + 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) + } else { + return fmt.Errorf("invalid --from flag input. please put \"registration\" or \"upgrade\"") } - return key.RetrieveAndStoreOraclePrivKey(ctx, svc, oracleRegistration.EncryptedOraclePrivKey) }, } + cmd.Flags().String(flags.FlagFromOracleRegistrationOrUpgrade, "upgrade", "where to get the key from (default \"upgrade\"") + return cmd } diff --git a/go.sum b/go.sum index a2c359f..093711c 100644 --- a/go.sum +++ b/go.sum @@ -1382,10 +1382,10 @@ 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= From 6d44c686ab3b25df03f71f72d83843bb05b0530a Mon Sep 17 00:00:00 2001 From: audtlr24 Date: Thu, 12 Jan 2023 16:53:31 +0900 Subject: [PATCH 2/5] fix --- cmd/oracled/cmd/get_oracle_key.go | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/oracled/cmd/get_oracle_key.go b/cmd/oracled/cmd/get_oracle_key.go index ae082b3..5853e11 100644 --- a/cmd/oracled/cmd/get_oracle_key.go +++ b/cmd/oracled/cmd/get_oracle_key.go @@ -62,7 +62,7 @@ func getOracleKeyCmd() *cobra.Command { }, } - cmd.Flags().String(flags.FlagFromOracleRegistrationOrUpgrade, "upgrade", "where to get the key from (default \"upgrade\"") + cmd.Flags().String(flags.FlagFromOracleRegistrationOrUpgrade, "upgrade", "where to get the key from") return cmd } diff --git a/go.mod b/go.mod index bda2723..a7823e9 100644 --- a/go.mod +++ b/go.mod @@ -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 From 0d297333eccfed46b74211e64d4d8ec5f6075c98 Mon Sep 17 00:00:00 2001 From: audtlr24 Date: Fri, 13 Jan 2023 11:55:17 +0900 Subject: [PATCH 3/5] fix: reflect comments --- cmd/oracled/cmd/get_oracle_key.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/oracled/cmd/get_oracle_key.go b/cmd/oracled/cmd/get_oracle_key.go index 5853e11..348f7b7 100644 --- a/cmd/oracled/cmd/get_oracle_key.go +++ b/cmd/oracled/cmd/get_oracle_key.go @@ -10,6 +10,11 @@ import ( "github.com/spf13/cobra" ) +const ( + fromRegistration = "registration" + fromUpgrade = "upgrade" +) + func getOracleKeyCmd() *cobra.Command { cmd := &cobra.Command{ Use: "get-oracle-key", @@ -35,7 +40,8 @@ func getOracleKeyCmd() *cobra.Command { return err } - if from == "registration" { + 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) @@ -46,7 +52,7 @@ func getOracleKeyCmd() *cobra.Command { } return key.RetrieveAndStoreOraclePrivKey(ctx, svc, oracleRegistration.EncryptedOraclePrivKey) - } else if from == "upgrade" { + case fromUpgrade: oracleUpgrade, err := svc.QueryClient().GetOracleUpgrade(ctx, uniqueID, oracleAddress) if err != nil { return fmt.Errorf("failed to get oracle upgrade: %w", err) @@ -55,10 +61,10 @@ func getOracleKeyCmd() *cobra.Command { return fmt.Errorf("the encrypted oracle private key has not set yet. please try again later") } return key.RetrieveAndStoreOraclePrivKey(ctx, svc, oracleUpgrade.EncryptedOraclePrivKey) - } else { + + default: return fmt.Errorf("invalid --from flag input. please put \"registration\" or \"upgrade\"") } - }, } From a17060a8dc550482a298af9396b94ac7763b0eca Mon Sep 17 00:00:00 2001 From: audtlr24 Date: Fri, 13 Jan 2023 14:00:05 +0900 Subject: [PATCH 4/5] fix: reflect comments --- cmd/oracled/cmd/get_oracle_key.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oracled/cmd/get_oracle_key.go b/cmd/oracled/cmd/get_oracle_key.go index 348f7b7..5c37f11 100644 --- a/cmd/oracled/cmd/get_oracle_key.go +++ b/cmd/oracled/cmd/get_oracle_key.go @@ -68,7 +68,7 @@ func getOracleKeyCmd() *cobra.Command { }, } - cmd.Flags().String(flags.FlagFromOracleRegistrationOrUpgrade, "upgrade", "where to get the key from") + cmd.Flags().String(flags.FlagFromOracleRegistrationOrUpgrade, fromUpgrade, "where to get the key from") return cmd } From 45eb25ee811b9fdf5ae82a4cc6679c90808b5c82 Mon Sep 17 00:00:00 2001 From: audtlr24 Date: Fri, 13 Jan 2023 14:32:01 +0900 Subject: [PATCH 5/5] fix --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 093711c..2fc4b3c 100644 --- a/go.sum +++ b/go.sum @@ -1382,8 +1382,6 @@ 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.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=