-
Notifications
You must be signed in to change notification settings - Fork 87
/
sig_type.go
64 lines (54 loc) · 1.33 KB
/
sig_type.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package idb
import (
"fmt"
"strings"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
)
// SigType is signature type.
type SigType string
// Possible signature types.
const (
Sig SigType = "sig"
Msig SigType = "msig"
Lsig SigType = "lsig"
)
var sigTypeEnumMap = map[SigType]struct{}{
Sig: {},
Msig: {},
Lsig: {},
}
func makeSigTypeEnumString() string {
keys := make([]string, 0, len(sigTypeEnumMap))
for k := range sigTypeEnumMap {
keys = append(keys, string(k))
}
return strings.Join(keys, ", ")
}
// SigTypeEnumString is a comma-separated list of possible signature types.
var SigTypeEnumString = makeSigTypeEnumString()
// IsSigTypeValid returns true if and only if `sigtype` is one of the possible
// signature types.
func IsSigTypeValid(sigtype SigType) bool {
_, ok := sigTypeEnumMap[sigtype]
return ok
}
// SignatureType returns the signature type of the given signed transaction.
func SignatureType(stxn *sdk.SignedTxn) (SigType, error) {
blankSignature := sdk.Signature{}
if stxn.Sig != blankSignature {
return Sig, nil
}
if !stxn.Msig.Blank() {
return Msig, nil
}
if !stxn.Lsig.Blank() {
if stxn.Lsig.Sig != blankSignature {
return Sig, nil
}
if !stxn.Lsig.Msig.Blank() {
return Msig, nil
}
return Lsig, nil
}
return "", fmt.Errorf("unable to determine the signature type for stxn=%+v", stxn)
}