-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelper.go
More file actions
49 lines (43 loc) · 1.29 KB
/
helper.go
File metadata and controls
49 lines (43 loc) · 1.29 KB
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
package model
import (
"math/big"
pb "github.com/blndgs/model/gen/go/proto/v1"
)
// ExtractSourceChainID retrieves the chain ID from the 'from' field of the intent.
func ExtractSourceChainID(intent *pb.Intent) (*big.Int, error) {
var chainIDProto *pb.BigInt
switch source := intent.From.(type) {
case *pb.Intent_FromAsset:
chainIDProto = source.FromAsset.GetChainId()
case *pb.Intent_FromLoan:
chainIDProto = source.FromLoan.GetChainId()
case *pb.Intent_FromStake:
chainIDProto = source.FromStake.GetChainId()
default:
return nil, ErrUnsupportedIntentType
}
chainID, err := ToBigInt(chainIDProto)
if err != nil {
return nil, ErrInvalidChainID
}
return chainID, nil
}
// ExtractDestinationChainID retrieves the chain ID from the 'to' field of the intent.
func ExtractDestinationChainID(intent *pb.Intent) (*big.Int, error) {
var chainIDProto *pb.BigInt
switch destination := intent.To.(type) {
case *pb.Intent_ToAsset:
chainIDProto = destination.ToAsset.GetChainId()
case *pb.Intent_ToLoan:
chainIDProto = destination.ToLoan.GetChainId()
case *pb.Intent_ToStake:
chainIDProto = destination.ToStake.GetChainId()
default:
return nil, ErrUnsupportedIntentType
}
chainID, err := ToBigInt(chainIDProto)
if err != nil {
return nil, ErrInvalidChainID
}
return chainID, nil
}