forked from ranjbar-dev/tron-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi-signature.go
40 lines (31 loc) · 903 Bytes
/
multi-signature.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
package tronWallet
import (
"crypto/ecdsa"
"errors"
"github.com/ranjbar-dev/tron-wallet/enums"
"github.com/ranjbar-dev/tron-wallet/grpcClient"
)
func CreateAndBroadcastMultiTransaction(node enums.Node, fromAddressBase58 string, toAddressBase58 string, amountInSun int64, privateKeys []*ecdsa.PrivateKey, _ ecdsa.PrivateKey) (string, error) {
transaction, err := createTransactionInput(node, fromAddressBase58, toAddressBase58, amountInSun)
if err != nil {
return "", err
}
for _, privateKey := range privateKeys {
transaction, err = signTransaction(transaction, privateKey)
if err != nil {
return "", err
}
}
c, err := grpcClient.GetGrpcClient(node)
if err != nil {
return "", err
}
res, err := c.Broadcast(transaction.Transaction)
if err != nil {
return "", err
}
if !res.Result {
return "", errors.New(res.Code.String())
}
return string(res.Message), nil
}