-
Notifications
You must be signed in to change notification settings - Fork 12
/
mixinnet_validation.go
50 lines (46 loc) · 1.07 KB
/
mixinnet_validation.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
package mixin
const (
ExtraSizeGeneralLimit = 256
ExtraSizeStorageStep = 1024
ExtraSizeStorageCapacity = 1024 * 1024 * 4
ExtraStoragePriceStep = "0.001"
SliceCountLimit = 256
ReferencesCountLimit = 2
)
var (
XINAssetId Hash
)
func init() {
XINAssetId = NewHash([]byte("c94ac88f-4671-3976-b60a-09064f1811e8"))
}
func (tx *Transaction) getExtraLimit() int {
if tx.Version < TxVersionReferences {
return ExtraSizeGeneralLimit
}
if tx.Asset != XINAssetId {
return ExtraSizeGeneralLimit
}
if len(tx.Outputs) < 1 {
return ExtraSizeGeneralLimit
}
out := tx.Outputs[0]
if len(out.Keys) != 1 {
return ExtraSizeGeneralLimit
}
if out.Type != OutputTypeScript {
return ExtraSizeGeneralLimit
}
if out.Script.String() != "fffe40" {
return ExtraSizeGeneralLimit
}
step := NewIntegerFromString(ExtraStoragePriceStep)
if out.Amount.Cmp(step) < 0 {
return ExtraSizeGeneralLimit
}
cells := out.Amount.Count(step)
limit := cells * ExtraSizeStorageStep
if limit > ExtraSizeStorageCapacity {
return ExtraSizeStorageCapacity
}
return int(limit)
}