-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.go
47 lines (37 loc) · 958 Bytes
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package actions
import (
"encoding/base64"
"github.com/fox-one/mixin-sdk-go"
"github.com/fox-one/pando/cmd/pando-cli/internal/cfg"
"github.com/fox-one/pando/core"
"github.com/fox-one/pando/pkg/mtg"
"github.com/fox-one/pando/pkg/uuid"
"github.com/spf13/cobra"
)
func Build(cmd *cobra.Command, values ...interface{}) (string, error) {
body, err := mtg.Encode(values...)
if err != nil {
return "", err
}
follow, _ := uuid.FromString(uuid.New())
cmd.Println("tx follow id:", follow)
action := core.TransactionAction{
FollowID: follow.Bytes(),
Body: body,
}
data, err := action.Encode()
if err != nil {
return "", err
}
key := mixin.GenerateEd25519Key()
pub := cfg.GetGroupVerify()
encryptedData, err := mtg.Encrypt(data, key, pub)
if err != nil {
return "", err
}
memo := base64.StdEncoding.EncodeToString(encryptedData)
if len(memo) > 200 {
memo = base64.StdEncoding.EncodeToString(data)
}
return memo, nil
}