diff --git a/ms_opt_receipt.go b/ms_opt_receipt.go index 844721c73..e85292343 100644 --- a/ms_opt_receipt.go +++ b/ms_opt_receipt.go @@ -253,11 +253,12 @@ func (j *jsonReceiptMilestoneOpt) ToSerializable() (serializer.Serializable, err } // ValidateReceipt validates whether given the following receipt: -// - None of the MigratedFundsEntry objects deposits more than the max supply and deposits at least -// MinMigratedFundsEntryDeposit tokens. -// - The sum of all migrated fund entries is not bigger than the total supply. -// - The previous unspent TreasuryOutput minus the sum of all migrated funds -// equals the amount of the new TreasuryOutput. +// - None of the MigratedFundsEntry objects deposits more than the max supply and deposits at least +// MinMigratedFundsEntryDeposit tokens. +// - The sum of all migrated fund entries is not bigger than the total supply. +// - The previous unspent TreasuryOutput minus the sum of all migrated funds +// equals the amount of the new TreasuryOutput. +// // This function panics if the receipt is nil, the receipt does not include any migrated fund entries or // the given treasury output is nil. func ValidateReceipt(receipt *ReceiptMilestoneOpt, prevTreasuryOutput *TreasuryOutput, totalSupply uint64) error { diff --git a/nodeclient/http.go b/nodeclient/http.go index ac427fbef..5be3dc2ad 100644 --- a/nodeclient/http.go +++ b/nodeclient/http.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" ) @@ -45,7 +44,7 @@ const ( ) func readBody(res *http.Response) ([]byte, error) { - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if err != nil { return nil, fmt.Errorf("unable to read response body: %w", err) } diff --git a/nodeclient/indexer_client_test.go b/nodeclient/indexer_client_test.go index 9d6c1d1d5..d4961c81c 100644 --- a/nodeclient/indexer_client_test.go +++ b/nodeclient/indexer_client_test.go @@ -18,21 +18,21 @@ func TestOutputsQuery_Build(t *testing.T) { trueCondition := true query := &nodeclient.BasicOutputsQuery{ IndexerTimelockParas: nodeclient.IndexerTimelockParas{ - HasTimelockCondition: &trueCondition, - TimelockedBefore: 1, - TimelockedAfter: 2, + HasTimelock: &trueCondition, + TimelockedBefore: 1, + TimelockedAfter: 2, }, IndexerExpirationParas: nodeclient.IndexerExpirationParas{ - HasExpirationCondition: &trueCondition, - ExpiresBefore: 5, - ExpiresAfter: 6, + HasExpiration: &trueCondition, + ExpiresBefore: 5, + ExpiresAfter: 6, }, IndexerCreationParas: nodeclient.IndexerCreationParas{ CreatedBefore: 9, CreatedAfter: 10, }, IndexerStorageDepositParas: nodeclient.IndexerStorageDepositParas{ - RequiresStorageDepositReturn: &trueCondition, + HasStorageDepositReturn: &trueCondition, StorageDepositReturnAddressBech32: "", }, AddressBech32: "alice", diff --git a/nodeclient/indexer_models.go b/nodeclient/indexer_models.go index c4cd21f92..c05854333 100644 --- a/nodeclient/indexer_models.go +++ b/nodeclient/indexer_models.go @@ -29,7 +29,7 @@ type IndexerCursorParas struct { // IndexerTimelockParas define timelock query parameters. type IndexerTimelockParas struct { // Filters outputs based on the presence of timelock unlock condition. - HasTimelockCondition *bool `qs:"hasTimelockCondition,omitempty"` + HasTimelock *bool `qs:"hasTimelock,omitempty"` // Return outputs that are timelocked before a certain Unix timestamp. TimelockedBefore uint32 `qs:"timelockedBefore,omitempty"` // Return outputs that are timelocked after a certain Unix timestamp. @@ -39,7 +39,7 @@ type IndexerTimelockParas struct { // IndexerExpirationParas define expiration query parameters. type IndexerExpirationParas struct { // Filters outputs based on the presence of expiration unlock condition. - HasExpirationCondition *bool `qs:"hasExpirationCondition,omitempty"` + HasExpiration *bool `qs:"hasExpiration,omitempty"` // Return outputs that expire before a certain Unix timestamp. ExpiresBefore uint32 `qs:"expiresBefore,omitempty"` // Return outputs that expire after a certain Unix timestamp. @@ -59,9 +59,9 @@ type IndexerCreationParas struct { // IndexerStorageDepositParas define storage deposit based query parameters. type IndexerStorageDepositParas struct { // Filters outputs based on the presence of storage deposit return unlock condition. - RequiresStorageDepositReturn *bool `qs:"requiresStorageDepositReturn,omitempty"` + HasStorageDepositReturn *bool `qs:"hasStorageDepositReturn,omitempty"` // Filter outputs based on the presence of a specific return address in the storage deposit return unlock condition. - StorageDepositReturnAddressBech32 string `qs:"storageDepositAddress,omitempty"` + StorageDepositReturnAddressBech32 string `qs:"storageDepositReturnAddress,omitempty"` } // BasicOutputsQuery defines parameters for an basic outputs query. diff --git a/output.go b/output.go index 8abeda0d0..93bb0c35a 100644 --- a/output.go +++ b/output.go @@ -9,9 +9,8 @@ import ( "sort" "strings" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" "golang.org/x/crypto/blake2b" "github.com/iotaledger/hive.go/serializer/v2" @@ -705,12 +704,12 @@ func (oih OutputIDHex) AsUTXOInput() (*UTXOInput, error) { type OutputsSyntacticalValidationFunc func(index int, output Output) error // OutputsSyntacticalDepositAmount returns an OutputsSyntacticalValidationFunc which checks that: -// - every output deposits more than zero -// - every output deposits less than the total supply -// - the sum of deposits does not exceed the total supply -// - the deposit fulfills the minimum storage deposit as calculated from the virtual byte cost of the output -// - if the output contains a StorageDepositReturnUnlockCondition, it must "return" bigger equal than the minimum storage deposit -// required for the sender to send back the tokens. +// - every output deposits more than zero +// - every output deposits less than the total supply +// - the sum of deposits does not exceed the total supply +// - the deposit fulfills the minimum storage deposit as calculated from the virtual byte cost of the output +// - if the output contains a StorageDepositReturnUnlockCondition, it must "return" bigger equal than the minimum storage deposit +// required for the sender to send back the tokens. func OutputsSyntacticalDepositAmount(protoParas *ProtocolParameters) OutputsSyntacticalValidationFunc { var sum uint64 return func(index int, output Output) error { @@ -747,8 +746,8 @@ func OutputsSyntacticalDepositAmount(protoParas *ProtocolParameters) OutputsSynt } // OutputsSyntacticalNativeTokens returns an OutputsSyntacticalValidationFunc which checks that: -// - the sum of native tokens count across all outputs does not exceed MaxNativeTokensCount -// - each native token holds an amount bigger than zero +// - the sum of native tokens count across all outputs does not exceed MaxNativeTokensCount +// - each native token holds an amount bigger than zero func OutputsSyntacticalNativeTokens() OutputsSyntacticalValidationFunc { var nativeTokensCount int return func(index int, output Output) error { @@ -790,8 +789,8 @@ func OutputsSyntacticalExpirationAndTimelock() OutputsSyntacticalValidationFunc } // OutputsSyntacticalAlias returns an OutputsSyntacticalValidationFunc which checks that AliasOutput(s)': -// - StateIndex/FoundryCounter are zero if the AliasID is zeroed -// - StateController and GovernanceController must be different from AliasAddress derived from AliasID +// - StateIndex/FoundryCounter are zero if the AliasID is zeroed +// - StateController and GovernanceController must be different from AliasAddress derived from AliasID func OutputsSyntacticalAlias() OutputsSyntacticalValidationFunc { return func(index int, output Output) error { aliasOutput, is := output.(*AliasOutput) @@ -823,8 +822,8 @@ func OutputsSyntacticalAlias() OutputsSyntacticalValidationFunc { } // OutputsSyntacticalFoundry returns an OutputsSyntacticalValidationFunc which checks that FoundryOutput(s)': -// - Minted and melted supply is less equal MaximumSupply -// - MaximumSupply is not zero +// - Minted and melted supply is less equal MaximumSupply +// - MaximumSupply is not zero func OutputsSyntacticalFoundry() OutputsSyntacticalValidationFunc { return func(index int, output Output) error { foundryOutput, is := output.(*FoundryOutput) @@ -841,7 +840,7 @@ func OutputsSyntacticalFoundry() OutputsSyntacticalValidationFunc { } // OutputsSyntacticalNFT returns an OutputsSyntacticalValidationFunc which checks that NFTOutput(s)': -// - Address must be different from NFTAddress derived from NFTID +// - Address must be different from NFTAddress derived from NFTID func OutputsSyntacticalNFT() OutputsSyntacticalValidationFunc { return func(index int, output Output) error { nftOutput, is := output.(*NFTOutput) diff --git a/output_alias.go b/output_alias.go index ebed4cbc3..567e67efe 100644 --- a/output_alias.go +++ b/output_alias.go @@ -291,13 +291,13 @@ func (a *AliasOutput) VBytes(rentStruct *RentStructure, _ VBytesFunc) uint64 { a.ImmutableFeatures.VBytes(rentStruct, nil) } -// - For output AliasOutput(s) with non-zeroed AliasID, there must be a corresponding input AliasOutput where either -// its AliasID is zeroed and StateIndex and FoundryCounter are zero or an input AliasOutput with the same AliasID. -// - On alias state transitions: -// - The StateIndex must be incremented by 1 -// - Only Amount, NativeTokens, StateIndex, StateMetadata and FoundryCounter can be mutated -// - On alias governance transition: -// - Only StateController (must be mutated), GovernanceController and the MetadataBlock can be mutated +// - For output AliasOutput(s) with non-zeroed AliasID, there must be a corresponding input AliasOutput where either +// its AliasID is zeroed and StateIndex and FoundryCounter are zero or an input AliasOutput with the same AliasID. +// - On alias state transitions: +// - The StateIndex must be incremented by 1 +// - Only Amount, NativeTokens, StateIndex, StateMetadata and FoundryCounter can be mutated +// - On alias governance transition: +// - Only StateController (must be mutated), GovernanceController and the MetadataBlock can be mutated func (a *AliasOutput) ValidateStateTransition(transType ChainTransitionType, next ChainConstrainedOutput, semValCtx *SemanticValidationContext) error { var err error switch transType { diff --git a/signature_test.go b/signature_test.go index 824679f90..3651dbf57 100644 --- a/signature_test.go +++ b/signature_test.go @@ -3,7 +3,7 @@ package iotago_test import ( "encoding/json" "errors" - "io/ioutil" + "os" "path/filepath" "testing" @@ -45,7 +45,7 @@ func TestEd25519Signature_Valid(t *testing.T) { } var tests []test // load the tests from file - b, err := ioutil.ReadFile(filepath.Join("testdata", t.Name()+".json")) + b, err := os.ReadFile(filepath.Join("testdata", t.Name()+".json")) require.NoError(t, err) require.NoError(t, json.Unmarshal(b, &tests)) diff --git a/transaction.go b/transaction.go index f14152ec1..7ddcb0bc4 100644 --- a/transaction.go +++ b/transaction.go @@ -701,9 +701,9 @@ func TxSemanticSTVFOnChains() TxSemanticValidationFunc { } // TxSemanticNativeTokens validates following rules regarding NativeTokens: -// - The NativeTokens between Inputs / Outputs must be balanced or have a deficit on the output side if -// there is no foundry state transition for a given NativeToken. -// - Max MaxNativeTokensCount native tokens within inputs + outputs +// - The NativeTokens between Inputs / Outputs must be balanced or have a deficit on the output side if +// there is no foundry state transition for a given NativeToken. +// - Max MaxNativeTokensCount native tokens within inputs + outputs func TxSemanticNativeTokens() TxSemanticValidationFunc { return func(svCtx *SemanticValidationContext) error { // native token set creates handle overflows diff --git a/unlock.go b/unlock.go index 9e7333239..1856802ac 100644 --- a/unlock.go +++ b/unlock.go @@ -177,8 +177,8 @@ type ReferentialUnlock interface { type UnlockValidatorFunc func(index int, unlock Unlock) error // UnlocksSigUniqueAndRefValidator returns a validator which checks that: -// 1. SignatureUnlock(s) are unique -// 2. ReferenceUnlock(s) reference a previous SignatureUnlock +// 1. SignatureUnlock(s) are unique +// 2. ReferenceUnlock(s) reference a previous SignatureUnlock // 3. Following through AliasUnlock(s), NFTUnlock(s) refs results to a SignatureUnlock func UnlocksSigUniqueAndRefValidator() UnlockValidatorFunc { seenSigUnlocks := map[uint16]struct{}{} diff --git a/unlock_cond.go b/unlock_cond.go index d912787d8..0d806d869 100644 --- a/unlock_cond.go +++ b/unlock_cond.go @@ -162,8 +162,9 @@ func (f UnlockConditionSet) HasTimelockCondition() bool { // tells whether the given ident can unlock an output containing this set of UnlockCondition(s) // when taking into consideration the constraints enforced by them: -// - If the timelocks are not expired, then nobody can unlock. -// - If the expiration blocks are expired, then only the return identity can unlock. +// - If the timelocks are not expired, then nobody can unlock. +// - If the expiration blocks are expired, then only the return identity can unlock. +// // returns booleans indicating whether the given ident can unlock and whether the return identity can unlock. func (f UnlockConditionSet) unlockableBy(ident Address, extParas *ExternalUnlockParameters) (givenIdentCanUnlock bool, returnIdentCanUnlock bool) { if err := f.TimelocksExpired(extParas); err != nil { diff --git a/unlock_cond_expiration.go b/unlock_cond_expiration.go index 14eac064d..2bca09417 100644 --- a/unlock_cond_expiration.go +++ b/unlock_cond_expiration.go @@ -17,8 +17,8 @@ var ( // ExpirationUnlockCondition is an unlock condition which puts a time constraint on whether the receiver or return identity // can consume an output depending on the latest confirmed milestone's timestamp T: -// - only the receiver identity can consume the output, if T is before than the one defined in the condition. -// - only the return identity can consume the output, if T is at the same time or after the one defined in the condition. +// - only the receiver identity can consume the output, if T is before than the one defined in the condition. +// - only the return identity can consume the output, if T is at the same time or after the one defined in the condition. type ExpirationUnlockCondition struct { // The identity who is allowed to use the output after the expiration has happened. ReturnAddress Address diff --git a/unlock_cond_timelock.go b/unlock_cond_timelock.go index 726d06e76..8f061df43 100644 --- a/unlock_cond_timelock.go +++ b/unlock_cond_timelock.go @@ -10,7 +10,7 @@ import ( // TimelockUnlockCondition is an unlock condition which puts a time constraint on an output depending // on the latest confirmed milestone's timestamp T: -// - the output can only be consumed, if T is bigger than the one defined in the condition. +// - the output can only be consumed, if T is bigger than the one defined in the condition. type TimelockUnlockCondition struct { // The unix time in second resolution until which the timelock applies (inclusive). UnixTime uint32