mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-26 12:57:26 +08:00
fix merge all
This commit is contained in:
parent
f848088c0c
commit
a113d3a39e
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
|
||||
"github.com/iden3/go-iden3-crypto/poseidon"
|
||||
"github.com/spf13/cobra"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
||||
)
|
||||
@ -27,36 +29,72 @@ var mergeCmd = &cobra.Command{
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
||||
client := protobufs.NewNodeServiceClient(conn)
|
||||
key, err := GetPrivKeyFromConfig(NodeConfig)
|
||||
peerId := GetPeerIDFromConfig(NodeConfig)
|
||||
privKey, err := GetPrivKeyFromConfig(NodeConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pub, err := privKey.GetPublic().Raw()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
addr, err := poseidon.HashBytes([]byte(peerId))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
addrBytes := addr.FillBytes(make([]byte, 32))
|
||||
|
||||
altAddr, err := poseidon.HashBytes([]byte(pub))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
altAddrBytes := altAddr.FillBytes(make([]byte, 32))
|
||||
|
||||
var coinaddrs []*protobufs.CoinRef
|
||||
|
||||
// Process for "merge all" command
|
||||
if len(args) == 1 && args[0] == "all" {
|
||||
// Make a new call to get all existing coins
|
||||
ctx := context.Background()
|
||||
response, err := client.GetCoins(ctx, &protobufs.GetCoinsRequest{})
|
||||
info, err := client.GetTokensByAccount(
|
||||
context.Background(),
|
||||
&protobufs.GetTokensByAccountRequest{
|
||||
Address: addrBytes,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Add all coins to the list
|
||||
for _, coin := range info.Addresses {
|
||||
coinaddrs = append(coinaddrs, &protobufs.CoinRef{
|
||||
Address: coin,
|
||||
})
|
||||
}
|
||||
info, err = client.GetTokensByAccount(
|
||||
context.Background(),
|
||||
&protobufs.GetTokensByAccountRequest{
|
||||
Address: altAddrBytes,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Add all coins to the list
|
||||
for _, coin := range info.Addresses {
|
||||
coinaddrs = append(coinaddrs, &protobufs.CoinRef{
|
||||
Address: coin,
|
||||
})
|
||||
}
|
||||
// Terminate if no coins available
|
||||
if len(response.Coins) == 0 {
|
||||
if len(coinaddrs) == 0 {
|
||||
println("No coins available to merge")
|
||||
return
|
||||
}
|
||||
|
||||
// Add all coins to the list
|
||||
for _, coin := range response.Coins {
|
||||
coinaddrs = append(coinaddrs, &protobufs.CoinRef{
|
||||
Address: coin.Address,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Regular coin address processing logic
|
||||
for _, arg := range args {
|
||||
@ -78,12 +116,7 @@ var mergeCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
// Signing process
|
||||
sig, err := key.Sign(payload)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pub, err := key.GetPublic().Raw()
|
||||
sig, err := privKey.Sign(payload)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user