-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.go
More file actions
36 lines (31 loc) · 711 Bytes
/
version.go
File metadata and controls
36 lines (31 loc) · 711 Bytes
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
package psbt
import (
"fmt"
"github.com/Techlateef/psbt/internal/compactsize"
"github.com/Techlateef/psbt/types"
)
func GetVersion(p *types.PSBT) (uint64, error) {
val, ok := getField(p.Global, types.PSBT_GLOBAL_VERSION)
if !ok {
return 0, nil // default version is 0 if not specified
}
v, err := compactsize.FromBytes(val)
if err != nil {
return 0, fmt.Errorf("invalid PSBT version encoding")
}
return v, nil
}
func IsV0(p *types.PSBT) (bool, error) {
version, err := GetVersion(p)
if err != nil {
return false, err
}
return version == 0, nil
}
func IsV2(p *types.PSBT) (bool, error) {
version, err := GetVersion(p)
if err != nil {
return false, err
}
return version == 2, nil
}