Skip to content

Commit

Permalink
ARCO-155: adjust to review - change names, remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszos4chain committed Jul 9, 2024
1 parent e36a251 commit 60a3c1b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,6 @@ func CommonValidateTransaction(policy *bitcoin.Settings, tx *bt.Tx) error {
return NewError(err, api.ErrStatusMalformed)
}

// // 10) Reject if the sum of input values is less than sum of output values
// // 11) Reject if transaction fee would be too low (minRelayTxFee) to get into an empty block.
// switch feeValidation {
// case StandardFeeValidation:
// if err := checkFees(tx, api.FeesToBtFeeQuote(policy.MinMiningTxFee)); err != nil {
// return NewError(err, api.ErrStatusFees)
// }
// case DeepFeeValidation:
// if err := v.deepCheckFees(ctx, tx, api.FeesToBtFeeQuote(policy.MinMiningTxFee)); err != nil {
// return NewError(err, api.ErrStatusFees) // TODO: add new status
// }
// default:
// }

// // 12) The unlocking scripts for each input must validate against the corresponding output locking scripts
// if scriptValidation == StandardScriptValidation {
// if err := checkScripts(tx); err != nil {
// return NewError(err, api.ErrStatusUnlockingScripts)
// }
// }

// everything checks out
return nil
}
Expand Down Expand Up @@ -157,12 +136,7 @@ func checkInputs(tx *bt.Tx) error {
if hex.EncodeToString(input.PreviousTxID()) == coinbaseTxID {
return NewError(fmt.Errorf("transaction input %d is a coinbase input", index), api.ErrStatusInputs)
}
/* lots of our valid test transactions have this sequence number, is this not allowed?
if input.SequenceNumber == 0xffffffff {
fmt.Printf("input %d has sequence number 0xffffffff, txid = %s", index, tx.TxID())
return validator.NewError(fmt.Errorf("transaction input %d sequence number is invalid", index), arc.ErrStatusInputs)
}
*/

if input.PreviousTxSatoshis > maxSatoshis {
return NewError(fmt.Errorf("transaction input %d satoshis is too high", index), api.ErrStatusInputs)
}
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions internal/validator/default/default_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func (v *DefaultValidator) ValidateTransaction(ctx context.Context, tx *bt.Tx, f
return err
}
case validator.NoneFeeValidation:
fallthrough
default:
// Do not handle the default case on purpose; we shouldn't assume that other types of validation should be omitted
}

// 12) The unlocking scripts for each input must validate against the corresponding output locking scripts
Expand Down
12 changes: 6 additions & 6 deletions internal/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ type BeefValidator interface {
type HexFormat byte

const (
Raw HexFormat = iota
Ef
Beef
RawHex HexFormat = iota
EfHex
BeefHex
)

func GetHexFormat(hex []byte) HexFormat {
if beef.CheckBeefFormat(hex) {
return Beef
return BeefHex
}

if isEf(hex) {
return Ef
return EfHex
}

return Raw
return RawHex
}

func isEf(hex []byte) bool {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/handler/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (m ArcDefaultHandler) POSTTransaction(ctx echo.Context, params api.POSTTran
var responseErr *api.ErrorFields

hexFormat := validator.GetHexFormat(transactionHex)
if hexFormat == validator.Beef {
if hexFormat == validator.BeefHex {
transaction, response, responseErr = m.processBEEFTransaction(ctx.Request().Context(), transactionHex, transactionOptions)
} else {
transaction, response, responseErr = m.processEFTransaction(ctx.Request().Context(), transactionHex, transactionOptions)
Expand Down Expand Up @@ -393,7 +393,7 @@ func (m ArcDefaultHandler) processTransactions(ctx context.Context, transactions
for len(transactionsHexes) != 0 {
hexFormat := validator.GetHexFormat(transactionsHexes)

if hexFormat == validator.Beef {
if hexFormat == validator.BeefHex {
beefTx, remainingBytes, err := beef.DecodeBEEF(transactionsHexes)
if err != nil {
errStr := fmt.Sprintf("error decoding BEEF: %s", err.Error())
Expand Down

0 comments on commit 60a3c1b

Please sign in to comment.