ceremonyclient/client/cmd/merge.go

81 lines
1.5 KiB
Go
Raw Normal View History

package cmd
import (
2024-10-14 01:37:19 +00:00
"context"
"encoding/hex"
"strings"
"github.com/spf13/cobra"
2024-10-14 01:37:19 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
)
var mergeCmd = &cobra.Command{
Use: "merge",
2024-10-14 01:37:19 +00:00
Short: "Merges multiple coins",
Long: `Merges multiple coins:
2024-10-14 01:37:19 +00:00
merge <Coin Addresses>...
`,
Run: func(cmd *cobra.Command, args []string) {
2024-10-14 01:37:19 +00:00
conn, err := GetGRPCClient()
if err != nil {
panic(err)
}
defer conn.Close()
client := protobufs.NewNodeServiceClient(conn)
key, err := GetPrivKeyFromConfig(NodeConfig)
if err != nil {
panic(err)
}
2024-10-14 01:37:19 +00:00
coinaddrs := []*protobufs.CoinRef{}
payload := []byte("merge")
for _, arg := range args {
coinaddrHex, _ := strings.CutPrefix(arg, "0x")
coinaddr, err := hex.DecodeString(coinaddrHex)
if err != nil {
panic(err)
}
coinaddrs = append(coinaddrs, &protobufs.CoinRef{
Address: coinaddr,
})
payload = append(payload, coinaddr...)
}
2024-10-14 01:37:19 +00:00
sig, err := key.Sign(payload)
if err != nil {
panic(err)
}
2024-10-14 01:37:19 +00:00
pub, err := key.GetPublic().Raw()
if err != nil {
panic(err)
}
_, err = client.SendMessage(
context.Background(),
&protobufs.TokenRequest{
Request: &protobufs.TokenRequest_Merge{
Merge: &protobufs.MergeCoinRequest{
Coins: coinaddrs,
Signature: &protobufs.Ed448Signature{
Signature: sig,
PublicKey: &protobufs.Ed448PublicKey{
KeyValue: pub,
},
},
},
},
},
)
if err != nil {
panic(err)
}
},
}
func init() {
tokenCmd.AddCommand(mergeCmd)
}