Skip to content

Commit

Permalink
added logic to recompute monew flew for send many where (tx transfer …
Browse files Browse the repository at this point in the history
…amount < total transfers + fee)
  • Loading branch information
0xluk authored and LINCKODE committed Jun 4, 2024
1 parent 1c2f8bb commit 47f627a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
59 changes: 49 additions & 10 deletions rpc/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit 47f627a

Please sign in to comment.