mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27:26 +08:00
* initial auto-update * working link, update, and testing docker container and scripts * refactor packages/folders * move files to proper folders * fix typos Closes #421 * optimize rpm imports * optimize channel imports * Refactor split command to allow testing of split operations Closes #338 * modify split and test for folder changes * remove alias * fix docker warning about FROM and AS being in different letter case Closes #422 * QClient Account Command * Display transaction details and confirmation prompts for transfer and merge commands * build qclient docker improvements * update build args for mpfr.so.6 * update install and node commands * remove NodeConfig check for qclient node commands * udpate * working node commands * update commands * move utils and rename package --------- Co-authored-by: Vasyl Tretiakov <vasyl.tretiakov@gmail.com> Co-authored-by: littleblackcloud <163544315+littleblackcloud@users.noreply.github.com> Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com> Co-authored-by: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com>
117 lines
2.5 KiB
Go
117 lines
2.5 KiB
Go
package token
|
||
|
||
import (
|
||
"context"
|
||
"encoding/hex"
|
||
"fmt"
|
||
"strings"
|
||
|
||
"github.com/spf13/cobra"
|
||
"source.quilibrium.com/quilibrium/monorepo/client/utils"
|
||
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
||
)
|
||
|
||
var transferCmd = &cobra.Command{
|
||
Use: "transfer",
|
||
Short: "Creates a pending transfer of coin",
|
||
Long: `Creates a pending transfer of coin:
|
||
transfer <ToAccount> <OfCoin>
|
||
ToAccount – account address, must be specified
|
||
OfCoin – the address of the coin to send in whole`,
|
||
Run: func(cmd *cobra.Command, args []string) {
|
||
if len(args) != 2 {
|
||
panic("invalid arguments")
|
||
}
|
||
|
||
conn, err := GetGRPCClient()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
defer conn.Close()
|
||
|
||
client := protobufs.NewNodeServiceClient(conn)
|
||
privKey, err := utils.GetPrivKeyFromConfig(NodeConfig)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
var coinaddr *protobufs.CoinRef
|
||
payload := []byte("transfer")
|
||
toaddr := []byte{}
|
||
|
||
for i, arg := range args {
|
||
addrHex, _ := strings.CutPrefix(arg, "0x")
|
||
addr, err := hex.DecodeString(addrHex)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
if i == 0 {
|
||
toaddr = addr
|
||
continue
|
||
}
|
||
coinaddr = &protobufs.CoinRef{
|
||
Address: addr,
|
||
}
|
||
payload = append(payload, addr...)
|
||
}
|
||
payload = append(payload, coinaddr.Address...)
|
||
|
||
// Display transaction details and confirmation prompt
|
||
fmt.Printf("\nTransaction Details:\n")
|
||
fmt.Printf("To Address: 0x%x\n", toaddr)
|
||
fmt.Printf("Coin Address: 0x%x\n", coinaddr.Address)
|
||
fmt.Print("\nDo you want to proceed with this transaction? (yes/no): ")
|
||
|
||
var response string
|
||
fmt.Scanln(&response)
|
||
|
||
if strings.ToLower(response) != "yes" {
|
||
fmt.Println("Transaction cancelled by user.")
|
||
return
|
||
}
|
||
|
||
sig, err := privKey.Sign(payload)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
pub, err := privKey.GetPublic().Raw()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
_, err = client.SendMessage(
|
||
context.Background(),
|
||
&protobufs.TokenRequest{
|
||
Request: &protobufs.TokenRequest_Transfer{
|
||
Transfer: &protobufs.TransferCoinRequest{
|
||
OfCoin: coinaddr,
|
||
ToAccount: &protobufs.AccountRef{
|
||
Account: &protobufs.AccountRef_ImplicitAccount{
|
||
ImplicitAccount: &protobufs.ImplicitAccount{
|
||
Address: toaddr,
|
||
},
|
||
},
|
||
},
|
||
Signature: &protobufs.Ed448Signature{
|
||
Signature: sig,
|
||
PublicKey: &protobufs.Ed448PublicKey{
|
||
KeyValue: pub,
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
fmt.Println("Transaction sent successfully.")
|
||
},
|
||
}
|
||
|
||
func init() {
|
||
TokenCmd.AddCommand(transferCmd)
|
||
}
|