- // special case for coinbase transaction, it's valid unit all the verify has been passed
- vs.gasStatus.GasValid = true
- case *bc.Claim:
- // 对交易的合法性进行验证
- if e.SpentOutputId == nil {
- return errors.Wrap(ErrMissingField, "spend without spent output ID")
- }
- spentOutput, err := vs.tx.Output(*e.SpentOutputId)
- if err != nil {
- return errors.Wrap(err, "getting spend prevout")
- }
- stack := e.GetPeginwitness()
- if len(stack) < 5 || stack[1] == nil || spentOutput.Source == nil {
-
- return errors.New("pegin-no-witness")
- }
-
- // 根据claim链类型选择验证类型
- validation := &claim.BytomClaimValidation{}
- if err := validation.IsValidPeginWitness(stack, *spentOutput); err != nil {
- return err
- }
-
- eq, err := spentOutput.Source.Value.Equal(e.WitnessDestination.Value)
- if err != nil {
- return err
- }
- if !eq {
- return errors.WithDetailf(
- ErrMismatchedValue,
- "previous output is for %d unit(s) of %x, spend wants %d unit(s) of %x",
- spentOutput.Source.Value.Amount,
- spentOutput.Source.Value.AssetId.Bytes(),
- e.WitnessDestination.Value.Amount,
- e.WitnessDestination.Value.AssetId.Bytes(),
- )
- }
-
- vs2 := *vs
- vs2.destPos = 0
- if err = checkValidDest(&vs2, e.WitnessDestination); err != nil {
- return errors.Wrap(err, "checking spend destination")
- }
- vs.gasStatus.GasValid = true