Skip to content

Commit ba26780

Browse files
authored
refactor: varying data enums (#62)
* refactor(varying-data): execution phase, pays * refactor(varying-data): transaction source * refactor(varying-data): unknown transaction * refactor(varying-data): invalid transaction * refactor(varying-data): inherents * refactor(varying-data): multisignature * refactor(varying-data): dispatch class * refactor(varying-data): multiaddress * refactor(varying-data): raw origin * refactor(varying-data): dispatch error
1 parent a563ba2 commit ba26780

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+723
-613
lines changed

build/runtime.wasm

-16.1 KB
Binary file not shown.

execution/extrinsic/dispatch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func GetDispatchInfo(xt types.CheckedExtrinsic) types.DispatchInfo {
5050
// TODO: Implement
5151
return types.DispatchInfo{
5252
Weight: types.WeightFromRefTime(sc.U64(len(xt.Bytes()))),
53-
Class: types.NewDispatchClass(types.NormalDispatch),
54-
PaysFee: types.NewPays(types.PaysYes),
53+
Class: types.NewDispatchClassNormal(),
54+
PaysFee: types.NewPaysYes(),
5555
}
5656

5757
case timestamp.Module.Index:

execution/extrinsic/unchecked.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func (uxt Unchecked) Check(lookup types.AccountIdLookup) (ok types.CheckedExtrin
1919

2020
rawPayload, err := NewSignedPayload(uxt.Function, extra)
2121
if err != nil {
22-
err = types.NewTransactionValidityError(types.NewUnknownTransaction(err))
22+
err = types.NewTransactionValidityError(err)
2323
return ok, err
2424
}
2525

2626
if !signature.Verify(rawPayload.UsingEncoded(), signedAddress) {
27-
err := types.NewTransactionValidityError(types.NewInvalidTransaction(types.BadProofError))
27+
err := types.NewTransactionValidityError(types.NewInvalidTransactionBadProof())
2828
return ok, err
2929
}
3030

execution/extrinsic/unsigned_validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ type UnsignedValidatorForChecked struct{}
2323
//
2424
// Changes made to storage *WILL* be persisted if the call returns `Ok`.
2525
func (v UnsignedValidatorForChecked) PreDispatch(call *types.Call) (ok sc.Empty, err types.TransactionValidityError) {
26-
_, err = v.ValidateUnsigned(types.NewTransactionSource(types.InBlock), call) // .map(|_| ()).map_err(Into::into)
26+
_, err = v.ValidateUnsigned(types.NewTransactionSourceInBlock(), call) // .map(|_| ()).map_err(Into::into)
2727
return ok, err
2828
}
2929

3030
// Information on a transaction's validity and, if valid, on how it relates to other transactions.
3131
// Inherent call is not validated as unsigned
3232
func (v UnsignedValidatorForChecked) ValidateUnsigned(_source types.TransactionSource, call *types.Call) (ok types.ValidTransaction, err types.TransactionValidityError) {
33-
noUnsignedValidatorError := types.NewTransactionValidityError(types.NewUnknownTransaction(types.NoUnsignedValidatorError))
33+
noUnsignedValidatorError := types.NewTransactionValidityError(types.NewUnknownTransactionNoUnsignedValidator())
3434
// TODO: Add more modules
3535
switch call.CallIndex.ModuleIndex {
3636
case system.Module.Index:

execution/inherent/check_inherents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func CheckInherents(data types.InherentData, block types.Block) types.CheckInher
2727
isInherent = true
2828
err := timestamp.CheckInherent(call, data)
2929
if err != nil {
30-
err := result.PutError(cts.InherentIdentifier, err)
30+
err := result.PutError(cts.InherentIdentifier, err.(types.IsFatalError))
3131
if err != nil {
3232
panic(err)
3333
}

frame/executive/executive.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func ApplyExtrinsic(uxt types.UncheckedExtrinsic) (ok types.DispatchOutcome, err
8181
//
8282
// The entire block should be discarded if an inherent fails to apply. Otherwise
8383
// it may open an attack vector.
84-
if res.HasError && dispatchInfo.Class.Is(types.MandatoryDispatch) {
85-
return ok, types.NewTransactionValidityError(types.NewInvalidTransaction(types.BadMandatoryError))
84+
if res.HasError && dispatchInfo.Class.Is(types.DispatchClassMandatory) {
85+
return ok, types.NewTransactionValidityError(types.NewInvalidTransactionBadMandatory())
8686
}
8787

8888
system.NoteAppliedExtrinsic(&res, dispatchInfo)
@@ -217,8 +217,8 @@ func ValidateTransaction(source types.TransactionSource, uxt types.UncheckedExtr
217217
log.Trace("dispatch_info")
218218
dispatchInfo := extrinsic.GetDispatchInfo(xt) // xt.GetDispatchInfo()
219219

220-
if dispatchInfo.Class.Is(types.MandatoryDispatch) {
221-
return ok, types.NewTransactionValidityError(types.NewInvalidTransaction(types.MandatoryValidationError))
220+
if dispatchInfo.Class.Is(types.DispatchClassMandatory) {
221+
return ok, types.NewTransactionValidityError(types.NewInvalidTransactionMandatoryValidation())
222222
}
223223

224224
log.Trace("validate")

frame/system/extensions/check_mortality.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func (e CheckMortality) AdditionalSigned() (ok types.H256, err types.Transaction
1111
n := sc.U32(types.Era(e).Birth(current)) // TODO: impl saturated_into::<T::BlockNumber>()
1212

1313
if !system.StorageExistsBlockHash(n) {
14-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.AncientBirthBlockError))
14+
err = types.NewTransactionValidityError(types.NewInvalidTransactionAncientBirthBlock())
1515
return ok, err
1616
} else {
1717
ok = types.H256(system.StorageGetBlockHash(n))

frame/system/extensions/check_non_zero_sender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (who CheckNonZeroAddress) Validate(_who *types.Address32, _call *types.Call
2626
return ok, err
2727
}
2828

29-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.BadSignerError))
29+
err = types.NewTransactionValidityError(types.NewInvalidTransactionBadSigner())
3030

3131
return ok, err
3232
}

frame/system/extensions/check_nonce.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (n CheckNonce) Validate(who *types.Address32, _call *types.Call, _info *typ
2020
account := system.StorageGetAccount((*who).FixedSequence)
2121

2222
if sc.U32(n) < account.Nonce {
23-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.StaleError))
23+
err = types.NewTransactionValidityError(types.NewInvalidTransactionStale())
2424
return ok, err
2525
}
2626

@@ -53,9 +53,9 @@ func (n CheckNonce) PreDispatch(who *types.Address32, call *types.Call, info *ty
5353

5454
if sc.U32(n) != account.Nonce {
5555
if sc.U32(n) < account.Nonce {
56-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.StaleError))
56+
err = types.NewTransactionValidityError(types.NewInvalidTransactionStale())
5757
} else {
58-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.FutureError))
58+
err = types.NewTransactionValidityError(types.NewInvalidTransactionFuture())
5959
}
6060
return ok, err
6161
}

frame/system/extensions/check_weight.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ func checkBlockLength(info *types.DispatchInfo, length sc.Compact) (ok sc.U32, e
9393
nextLen := currentLen.SaturatingAdd(addedLen)
9494

9595
var maxLimit sc.U32
96-
if info.Class.Is(types.NormalDispatch) {
96+
if info.Class.Is(types.DispatchClassNormal) {
9797
maxLimit = lengthLimit.Max.Normal
98-
} else if info.Class.Is(types.OperationalDispatch) {
98+
} else if info.Class.Is(types.DispatchClassOperational) {
9999
maxLimit = lengthLimit.Max.Operational
100-
} else if info.Class.Is(types.MandatoryDispatch) {
100+
} else if info.Class.Is(types.DispatchClassMandatory) {
101101
maxLimit = lengthLimit.Max.Mandatory
102102
} else {
103103
log.Critical("invalid DispatchClass type in CheckBlockLength()")
104104
}
105105

106106
if nextLen > maxLimit {
107-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.ExhaustsResourcesError))
107+
err = types.NewTransactionValidityError(types.NewInvalidTransactionExhaustsResources())
108108
} else {
109109
ok = sc.U32(sc.ToCompact(nextLen).ToBigInt().Uint64())
110110
}
@@ -119,7 +119,7 @@ func checkExtrinsicWeight(info *types.DispatchInfo) (ok sc.Empty, err types.Tran
119119

120120
if max.HasValue {
121121
if info.Weight.AnyGt(max.Value) {
122-
err = types.NewTransactionValidityError(types.NewInvalidTransaction(types.ExhaustsResourcesError))
122+
err = types.NewTransactionValidityError(types.NewInvalidTransactionExhaustsResources())
123123
} else {
124124
ok = sc.Empty{}
125125
}

0 commit comments

Comments
 (0)