From 47f627af8823e9dd9f921578d34c5d9cbb1e198d Mon Sep 17 00:00:00 2001 From: 0xluk Date: Sun, 2 Jun 2024 03:05:01 +0300 Subject: [PATCH] added logic to recompute monew flew for send many where (tx transfer amount < total transfers + fee) --- go.mod | 2 +- go.sum | 4 ++-- rpc/rpc_server.go | 59 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 75aa6ca..7d879b8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/google/go-cmp v0.6.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 github.com/pkg/errors v0.9.1 - github.com/qubic/go-node-connector v0.6.2 + github.com/qubic/go-node-connector v0.7.1 github.com/qubic/go-schnorrq v1.0.0 github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.26.0 diff --git a/go.sum b/go.sum index 05f411f..9295542 100644 --- a/go.sum +++ b/go.sum @@ -232,8 +232,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/qubic/go-node-connector v0.6.2 h1:g2KrmoN+hH+pUXGup3KKN7lvOLpiN0RV4EaDtWJ8Ovs= -github.com/qubic/go-node-connector v0.6.2/go.mod h1:iToCz9g9C0lWcah5gjnn16tQHdz6vvRNB0S7kKgARVU= +github.com/qubic/go-node-connector v0.7.1 h1:AvkirqMTW6PQ7VxvALJOSI2+Cja3cl1llwFqWftaD6I= +github.com/qubic/go-node-connector v0.7.1/go.mod h1:3Q9xCv5c01AqxVIx1aijMd8Pt3KJyQQiDfc4sG0UnXI= github.com/qubic/go-schnorrq v1.0.0 h1:EiCC3v9v3esFFfhKNEGdAI4DFIY3Dm/wbH327pC5qco= github.com/qubic/go-schnorrq v1.0.0/go.mod h1:KW64PcvyF4+cBA22pCx9wcoKDqPIbGz0EZ9dCZWV6Yo= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/rpc/rpc_server.go b/rpc/rpc_server.go index da04d9b..4485fd5 100644 --- a/rpc/rpc_server.go +++ b/rpc/rpc_server.go @@ -398,20 +398,32 @@ func (s *Server) GetTickApprovedTransactions(ctx context.Context, req *protobuff continue } - storedTx, err := s.store.GetTransaction(ctx, txStatus.TxId) + tx, err := s.store.GetTransaction(ctx, txStatus.TxId) if err != nil { return nil, errors.Wrapf(err, "getting tx %s from archiver", txStatus.TxId) } + + if tx.InputType == 1 && tx.InputSize == 1000 && tx.DestId == "EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVWRF" { + moneyFlew, err := recomputeSendManyMoneyFlew(tx) + if err != nil { + return nil, status.Errorf(codes.Internal, "recomputeSendManyMoneyFlew: %v", err) + } + + if moneyFlew == false { + continue + } + } + approvedTxs = append(approvedTxs, &protobuff.Transaction{ - SourceId: storedTx.SourceId, - DestId: storedTx.DestId, - Amount: storedTx.Amount, - TickNumber: storedTx.TickNumber, - InputType: storedTx.InputType, - InputSize: storedTx.InputSize, - InputHex: storedTx.InputHex, - SignatureHex: storedTx.SignatureHex, - TxId: storedTx.TxId, + SourceId: tx.SourceId, + DestId: tx.DestId, + Amount: tx.Amount, + TickNumber: tx.TickNumber, + InputType: tx.InputType, + InputSize: tx.InputSize, + InputHex: tx.InputHex, + SignatureHex: tx.SignatureHex, + TxId: tx.TxId, }) } @@ -482,6 +494,15 @@ func (s *Server) GetTransactionStatus(ctx context.Context, req *protobuff.GetTra return nil, status.Errorf(codes.Internal, "getting tx status: %v", err) } + if tx.InputType == 1 && tx.InputSize == 1000 && tx.DestId == "EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVWRF" { + moneyFlew, err := recomputeSendManyMoneyFlew(tx) + if err != nil { + return nil, status.Errorf(codes.Internal, "recomputeSendManyMoneyFlew: %v", err) + } + + return &protobuff.GetTransactionStatusResponse{TransactionStatus: &protobuff.TransactionStatus{TxId: tx.TxId, MoneyFlew: moneyFlew}}, nil + } + return &protobuff.GetTransactionStatusResponse{TransactionStatus: txStatus}, nil } @@ -558,3 +579,21 @@ func (s *Server) Start() error { return nil } + +func recomputeSendManyMoneyFlew(tx *protobuff.Transaction) (bool, error) { + decodedInput, err := hex.DecodeString(tx.InputHex) + if err != nil { + return false, status.Errorf(codes.Internal, "decoding tx input: %v", err) + } + var sendmanypayload types.SendManyTransferPayload + err = sendmanypayload.UnmarshallBinary(decodedInput) + if err != nil { + return false, status.Errorf(codes.Internal, "unmarshalling payload: %v", err) + } + + if tx.Amount < sendmanypayload.GetTotalAmount() { + return false, nil + } + + return true, nil +}