Skip to content

601 multisig validation #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/transaction/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func init() {
"`Sender Account Address` field of the transaction")
txCmd.PersistentFlags().StringVar(&recipientAccountAddress, "recipient", "", "defines the recipient intended for the transaction")
txCmd.PersistentFlags().Int64Var(&fee, "fee", 1, "defines the fee of the transaction")
txCmd.PersistentFlags().BoolVar(&post, "post", false, "post generated bytes to [127.0.0.1:7000](default)")
txCmd.PersistentFlags().StringVar(&postHost, "post-host", "127.0.0.1:7000", "destination of post action")

/*
SendMoney Command
Expand Down
2 changes: 2 additions & 0 deletions cmd/transaction/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (
senderSeed string
recipientAccountAddress string
fee int64
post bool
postHost string

// Send money transaction
sendAmount int64
Expand Down
27 changes: 26 additions & 1 deletion cmd/transaction/generator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package transaction

import (
"context"
"database/sql"
"encoding/hex"
"fmt"
"log"
"strings"
"time"

rpc_model "github.com/zoobc/zoobc-core/common/model"
rpc_service "github.com/zoobc/zoobc-core/common/service"
"google.golang.org/grpc"

"github.com/zoobc/zoobc-core/common/chaintype"
"github.com/zoobc/zoobc-core/common/constant"
"github.com/zoobc/zoobc-core/common/crypto"
Expand Down Expand Up @@ -262,7 +268,26 @@ func PrintTx(signedTxBytes []byte, outputType string) {
}
resultStr = strings.Join(byteStrArr, ", ")
}
fmt.Println(resultStr)
if post {
conn, err := grpc.Dial(postHost, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %s", err)
}
defer conn.Close()

c := rpc_service.NewTransactionServiceClient(conn)

response, err := c.PostTransaction(context.Background(), &rpc_model.PostTransactionRequest{
TransactionBytes: signedTxBytes,
})
if err != nil {
fmt.Printf("post failed: %v\n", err)
} else {
fmt.Printf("\n\nresult: %v\n", response)
}
} else {
fmt.Println(resultStr)
}
}

func GenerateSignedTxBytes(tx *model.Transaction, senderSeed string) []byte {
Expand Down
85 changes: 82 additions & 3 deletions common/transaction/multiSignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package transaction
import (
"bytes"

"github.com/zoobc/zoobc-core/common/crypto"

"github.com/zoobc/zoobc-core/common/blocker"

"github.com/zoobc/zoobc-core/common/constant"
"github.com/zoobc/zoobc-core/common/fee"
"github.com/zoobc/zoobc-core/common/model"
Expand All @@ -13,8 +17,11 @@ type (
// MultiSignatureTransaction represent wrapper transaction type that require multiple signer to approve the transcaction
// wrapped
MultiSignatureTransaction struct {
Body *model.MultiSignatureTransactionBody
NormalFee fee.FeeModelInterface
Body *model.MultiSignatureTransactionBody
NormalFee fee.FeeModelInterface
TransactionUtil UtilInterface
TypeSwitcher TypeActionSwitcher
Signature crypto.SignatureInterface
}
)

Expand All @@ -31,7 +38,79 @@ func (*MultiSignatureTransaction) UndoApplyUnconfirmed() error {
}

// Validate dbTx specify whether validation should read from transaction state or db state
func (*MultiSignatureTransaction) Validate(dbTx bool) error {
func (tx *MultiSignatureTransaction) Validate(dbTx bool) error {
body := tx.Body
if body.MultiSignatureInfo == nil && body.SignatureInfo == nil && body.UnsignedTransactionBytes == nil {
return blocker.NewBlocker(blocker.ValidationErr, "AtLeastTxBytesSignatureInfoOrMultisignatureInfoMustBe"+
"Provided")
}
if body.MultiSignatureInfo != nil {
if len(body.MultiSignatureInfo.Addresses) < 2 {
return blocker.NewBlocker(
blocker.ValidationErr,
"AtLeastTwoParticipantRequiredForMultisig",
)
}
if body.MultiSignatureInfo.MinimumSignatures < 1 {
return blocker.NewBlocker(
blocker.ValidationErr,
"AtLeastOneSignatureRequiredNeedToBeSet",
)
}
}
if len(body.UnsignedTransactionBytes) > 0 {
innerTx, err := tx.TransactionUtil.ParseTransactionBytes(tx.Body.UnsignedTransactionBytes, false)
if err != nil {
return blocker.NewBlocker(
blocker.ValidationErr,
"FailToParseTransactionBytes",
)
}
innerTa, err := tx.TypeSwitcher.GetTransactionType(innerTx)
if err != nil {
return blocker.NewBlocker(
blocker.ValidationErr,
"FailToCastInnerTransaction",
)
}
err = innerTa.Validate(dbTx)
if err != nil {
return blocker.NewBlocker(
blocker.ValidationErr,
"FailToValidateInnerTa",
)
}

}
if body.SignatureInfo != nil {
if body.SignatureInfo.TransactionHash == nil { // transaction hash has to come with at least one signature
return blocker.NewBlocker(
blocker.ValidationErr,
"TransactionHashRequiredInSignatureInfo",
)
}
if len(body.SignatureInfo.Signatures) < 1 {
return blocker.NewBlocker(
blocker.ValidationErr,
"MinimumOneSignatureRequiredInSignatureInfo",
)
}
for addr, sig := range body.SignatureInfo.Signatures {
if sig == nil {
return blocker.NewBlocker(
blocker.ValidationErr,
"SignatureMissing",
)
}
res := tx.Signature.VerifySignature(body.SignatureInfo.TransactionHash, sig, addr)
if !res {
return blocker.NewBlocker(
blocker.ValidationErr,
"InvalidSignature",
)
}
}
}
return nil
}

Expand Down
Loading