@@ -3,6 +3,10 @@ package transaction
3
3
import (
4
4
"bytes"
5
5
6
+ "github.com/zoobc/zoobc-core/common/crypto"
7
+
8
+ "github.com/zoobc/zoobc-core/common/blocker"
9
+
6
10
"github.com/zoobc/zoobc-core/common/constant"
7
11
"github.com/zoobc/zoobc-core/common/fee"
8
12
"github.com/zoobc/zoobc-core/common/model"
@@ -13,8 +17,11 @@ type (
13
17
// MultiSignatureTransaction represent wrapper transaction type that require multiple signer to approve the transcaction
14
18
// wrapped
15
19
MultiSignatureTransaction struct {
16
- Body * model.MultiSignatureTransactionBody
17
- NormalFee fee.FeeModelInterface
20
+ Body * model.MultiSignatureTransactionBody
21
+ NormalFee fee.FeeModelInterface
22
+ TransactionUtil UtilInterface
23
+ TypeSwitcher TypeActionSwitcher
24
+ Signature crypto.SignatureInterface
18
25
}
19
26
)
20
27
@@ -31,7 +38,79 @@ func (*MultiSignatureTransaction) UndoApplyUnconfirmed() error {
31
38
}
32
39
33
40
// Validate dbTx specify whether validation should read from transaction state or db state
34
- func (* MultiSignatureTransaction ) Validate (dbTx bool ) error {
41
+ func (tx * MultiSignatureTransaction ) Validate (dbTx bool ) error {
42
+ body := tx .Body
43
+ if body .MultiSignatureInfo == nil && body .SignatureInfo == nil && body .UnsignedTransactionBytes == nil {
44
+ return blocker .NewBlocker (blocker .ValidationErr , "AtLeastTxBytesSignatureInfoOrMultisignatureInfoMustBe" +
45
+ "Provided" )
46
+ }
47
+ if body .MultiSignatureInfo != nil {
48
+ if len (body .MultiSignatureInfo .Addresses ) < 2 {
49
+ return blocker .NewBlocker (
50
+ blocker .ValidationErr ,
51
+ "AtLeastTwoParticipantRequiredForMultisig" ,
52
+ )
53
+ }
54
+ if body .MultiSignatureInfo .MinimumSignatures < 1 {
55
+ return blocker .NewBlocker (
56
+ blocker .ValidationErr ,
57
+ "AtLeastOneSignatureRequiredNeedToBeSet" ,
58
+ )
59
+ }
60
+ }
61
+ if len (body .UnsignedTransactionBytes ) > 0 {
62
+ innerTx , err := tx .TransactionUtil .ParseTransactionBytes (tx .Body .UnsignedTransactionBytes , false )
63
+ if err != nil {
64
+ return blocker .NewBlocker (
65
+ blocker .ValidationErr ,
66
+ "FailToParseTransactionBytes" ,
67
+ )
68
+ }
69
+ innerTa , err := tx .TypeSwitcher .GetTransactionType (innerTx )
70
+ if err != nil {
71
+ return blocker .NewBlocker (
72
+ blocker .ValidationErr ,
73
+ "FailToCastInnerTransaction" ,
74
+ )
75
+ }
76
+ err = innerTa .Validate (dbTx )
77
+ if err != nil {
78
+ return blocker .NewBlocker (
79
+ blocker .ValidationErr ,
80
+ "FailToValidateInnerTa" ,
81
+ )
82
+ }
83
+
84
+ }
85
+ if body .SignatureInfo != nil {
86
+ if body .SignatureInfo .TransactionHash == nil { // transaction hash has to come with at least one signature
87
+ return blocker .NewBlocker (
88
+ blocker .ValidationErr ,
89
+ "TransactionHashRequiredInSignatureInfo" ,
90
+ )
91
+ }
92
+ if len (body .SignatureInfo .Signatures ) < 1 {
93
+ return blocker .NewBlocker (
94
+ blocker .ValidationErr ,
95
+ "MinimumOneSignatureRequiredInSignatureInfo" ,
96
+ )
97
+ }
98
+ for addr , sig := range body .SignatureInfo .Signatures {
99
+ if sig == nil {
100
+ return blocker .NewBlocker (
101
+ blocker .ValidationErr ,
102
+ "SignatureMissing" ,
103
+ )
104
+ }
105
+ res := tx .Signature .VerifySignature (body .SignatureInfo .TransactionHash , sig , addr )
106
+ if ! res {
107
+ return blocker .NewBlocker (
108
+ blocker .ValidationErr ,
109
+ "InvalidSignature" ,
110
+ )
111
+ }
112
+ }
113
+ }
35
114
return nil
36
115
}
37
116
0 commit comments