Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit ad22ee9

Browse files
authored
- Renamed fields in indexer to match implementation and spec (#404)
* - Renamed fields in indexer to match implementation and spec * - Fixed reviewdog comments * - gofmt all the things
1 parent 652becc commit ad22ee9

12 files changed

+52
-52
lines changed

ms_opt_receipt.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,12 @@ func (j *jsonReceiptMilestoneOpt) ToSerializable() (serializer.Serializable, err
253253
}
254254

255255
// ValidateReceipt validates whether given the following receipt:
256-
// - None of the MigratedFundsEntry objects deposits more than the max supply and deposits at least
257-
// MinMigratedFundsEntryDeposit tokens.
258-
// - The sum of all migrated fund entries is not bigger than the total supply.
259-
// - The previous unspent TreasuryOutput minus the sum of all migrated funds
260-
// equals the amount of the new TreasuryOutput.
256+
// - None of the MigratedFundsEntry objects deposits more than the max supply and deposits at least
257+
// MinMigratedFundsEntryDeposit tokens.
258+
// - The sum of all migrated fund entries is not bigger than the total supply.
259+
// - The previous unspent TreasuryOutput minus the sum of all migrated funds
260+
// equals the amount of the new TreasuryOutput.
261+
//
261262
// This function panics if the receipt is nil, the receipt does not include any migrated fund entries or
262263
// the given treasury output is nil.
263264
func ValidateReceipt(receipt *ReceiptMilestoneOpt, prevTreasuryOutput *TreasuryOutput, totalSupply uint64) error {

nodeclient/http.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net/http"
1211
"net/url"
1312
)
@@ -45,7 +44,7 @@ const (
4544
)
4645

4746
func readBody(res *http.Response) ([]byte, error) {
48-
resBody, err := ioutil.ReadAll(res.Body)
47+
resBody, err := io.ReadAll(res.Body)
4948
if err != nil {
5049
return nil, fmt.Errorf("unable to read response body: %w", err)
5150
}

nodeclient/indexer_client_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ func TestOutputsQuery_Build(t *testing.T) {
1818
trueCondition := true
1919
query := &nodeclient.BasicOutputsQuery{
2020
IndexerTimelockParas: nodeclient.IndexerTimelockParas{
21-
HasTimelockCondition: &trueCondition,
22-
TimelockedBefore: 1,
23-
TimelockedAfter: 2,
21+
HasTimelock: &trueCondition,
22+
TimelockedBefore: 1,
23+
TimelockedAfter: 2,
2424
},
2525
IndexerExpirationParas: nodeclient.IndexerExpirationParas{
26-
HasExpirationCondition: &trueCondition,
27-
ExpiresBefore: 5,
28-
ExpiresAfter: 6,
26+
HasExpiration: &trueCondition,
27+
ExpiresBefore: 5,
28+
ExpiresAfter: 6,
2929
},
3030
IndexerCreationParas: nodeclient.IndexerCreationParas{
3131
CreatedBefore: 9,
3232
CreatedAfter: 10,
3333
},
3434
IndexerStorageDepositParas: nodeclient.IndexerStorageDepositParas{
35-
RequiresStorageDepositReturn: &trueCondition,
35+
HasStorageDepositReturn: &trueCondition,
3636
StorageDepositReturnAddressBech32: "",
3737
},
3838
AddressBech32: "alice",

nodeclient/indexer_models.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type IndexerCursorParas struct {
2929
// IndexerTimelockParas define timelock query parameters.
3030
type IndexerTimelockParas struct {
3131
// Filters outputs based on the presence of timelock unlock condition.
32-
HasTimelockCondition *bool `qs:"hasTimelockCondition,omitempty"`
32+
HasTimelock *bool `qs:"hasTimelock,omitempty"`
3333
// Return outputs that are timelocked before a certain Unix timestamp.
3434
TimelockedBefore uint32 `qs:"timelockedBefore,omitempty"`
3535
// Return outputs that are timelocked after a certain Unix timestamp.
@@ -39,7 +39,7 @@ type IndexerTimelockParas struct {
3939
// IndexerExpirationParas define expiration query parameters.
4040
type IndexerExpirationParas struct {
4141
// Filters outputs based on the presence of expiration unlock condition.
42-
HasExpirationCondition *bool `qs:"hasExpirationCondition,omitempty"`
42+
HasExpiration *bool `qs:"hasExpiration,omitempty"`
4343
// Return outputs that expire before a certain Unix timestamp.
4444
ExpiresBefore uint32 `qs:"expiresBefore,omitempty"`
4545
// Return outputs that expire after a certain Unix timestamp.
@@ -59,9 +59,9 @@ type IndexerCreationParas struct {
5959
// IndexerStorageDepositParas define storage deposit based query parameters.
6060
type IndexerStorageDepositParas struct {
6161
// Filters outputs based on the presence of storage deposit return unlock condition.
62-
RequiresStorageDepositReturn *bool `qs:"requiresStorageDepositReturn,omitempty"`
62+
HasStorageDepositReturn *bool `qs:"hasStorageDepositReturn,omitempty"`
6363
// Filter outputs based on the presence of a specific return address in the storage deposit return unlock condition.
64-
StorageDepositReturnAddressBech32 string `qs:"storageDepositAddress,omitempty"`
64+
StorageDepositReturnAddressBech32 string `qs:"storageDepositReturnAddress,omitempty"`
6565
}
6666

6767
// BasicOutputsQuery defines parameters for an basic outputs query.

output.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import (
99
"sort"
1010
"strings"
1111

12-
"github.com/ethereum/go-ethereum/common"
13-
1412
"github.com/ethereum/go-ethereum/accounts/abi"
13+
"github.com/ethereum/go-ethereum/common"
1514
"golang.org/x/crypto/blake2b"
1615

1716
"github.com/iotaledger/hive.go/serializer/v2"
@@ -705,12 +704,12 @@ func (oih OutputIDHex) AsUTXOInput() (*UTXOInput, error) {
705704
type OutputsSyntacticalValidationFunc func(index int, output Output) error
706705

707706
// OutputsSyntacticalDepositAmount returns an OutputsSyntacticalValidationFunc which checks that:
708-
// - every output deposits more than zero
709-
// - every output deposits less than the total supply
710-
// - the sum of deposits does not exceed the total supply
711-
// - the deposit fulfills the minimum storage deposit as calculated from the virtual byte cost of the output
712-
// - if the output contains a StorageDepositReturnUnlockCondition, it must "return" bigger equal than the minimum storage deposit
713-
// required for the sender to send back the tokens.
707+
// - every output deposits more than zero
708+
// - every output deposits less than the total supply
709+
// - the sum of deposits does not exceed the total supply
710+
// - the deposit fulfills the minimum storage deposit as calculated from the virtual byte cost of the output
711+
// - if the output contains a StorageDepositReturnUnlockCondition, it must "return" bigger equal than the minimum storage deposit
712+
// required for the sender to send back the tokens.
714713
func OutputsSyntacticalDepositAmount(protoParas *ProtocolParameters) OutputsSyntacticalValidationFunc {
715714
var sum uint64
716715
return func(index int, output Output) error {
@@ -747,8 +746,8 @@ func OutputsSyntacticalDepositAmount(protoParas *ProtocolParameters) OutputsSynt
747746
}
748747

749748
// OutputsSyntacticalNativeTokens returns an OutputsSyntacticalValidationFunc which checks that:
750-
// - the sum of native tokens count across all outputs does not exceed MaxNativeTokensCount
751-
// - each native token holds an amount bigger than zero
749+
// - the sum of native tokens count across all outputs does not exceed MaxNativeTokensCount
750+
// - each native token holds an amount bigger than zero
752751
func OutputsSyntacticalNativeTokens() OutputsSyntacticalValidationFunc {
753752
var nativeTokensCount int
754753
return func(index int, output Output) error {
@@ -790,8 +789,8 @@ func OutputsSyntacticalExpirationAndTimelock() OutputsSyntacticalValidationFunc
790789
}
791790

792791
// OutputsSyntacticalAlias returns an OutputsSyntacticalValidationFunc which checks that AliasOutput(s)':
793-
// - StateIndex/FoundryCounter are zero if the AliasID is zeroed
794-
// - StateController and GovernanceController must be different from AliasAddress derived from AliasID
792+
// - StateIndex/FoundryCounter are zero if the AliasID is zeroed
793+
// - StateController and GovernanceController must be different from AliasAddress derived from AliasID
795794
func OutputsSyntacticalAlias() OutputsSyntacticalValidationFunc {
796795
return func(index int, output Output) error {
797796
aliasOutput, is := output.(*AliasOutput)
@@ -823,8 +822,8 @@ func OutputsSyntacticalAlias() OutputsSyntacticalValidationFunc {
823822
}
824823

825824
// OutputsSyntacticalFoundry returns an OutputsSyntacticalValidationFunc which checks that FoundryOutput(s)':
826-
// - Minted and melted supply is less equal MaximumSupply
827-
// - MaximumSupply is not zero
825+
// - Minted and melted supply is less equal MaximumSupply
826+
// - MaximumSupply is not zero
828827
func OutputsSyntacticalFoundry() OutputsSyntacticalValidationFunc {
829828
return func(index int, output Output) error {
830829
foundryOutput, is := output.(*FoundryOutput)
@@ -841,7 +840,7 @@ func OutputsSyntacticalFoundry() OutputsSyntacticalValidationFunc {
841840
}
842841

843842
// OutputsSyntacticalNFT returns an OutputsSyntacticalValidationFunc which checks that NFTOutput(s)':
844-
// - Address must be different from NFTAddress derived from NFTID
843+
// - Address must be different from NFTAddress derived from NFTID
845844
func OutputsSyntacticalNFT() OutputsSyntacticalValidationFunc {
846845
return func(index int, output Output) error {
847846
nftOutput, is := output.(*NFTOutput)

output_alias.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ func (a *AliasOutput) VBytes(rentStruct *RentStructure, _ VBytesFunc) uint64 {
291291
a.ImmutableFeatures.VBytes(rentStruct, nil)
292292
}
293293

294-
// - For output AliasOutput(s) with non-zeroed AliasID, there must be a corresponding input AliasOutput where either
295-
// its AliasID is zeroed and StateIndex and FoundryCounter are zero or an input AliasOutput with the same AliasID.
296-
// - On alias state transitions:
297-
// - The StateIndex must be incremented by 1
298-
// - Only Amount, NativeTokens, StateIndex, StateMetadata and FoundryCounter can be mutated
299-
// - On alias governance transition:
300-
// - Only StateController (must be mutated), GovernanceController and the MetadataBlock can be mutated
294+
// - For output AliasOutput(s) with non-zeroed AliasID, there must be a corresponding input AliasOutput where either
295+
// its AliasID is zeroed and StateIndex and FoundryCounter are zero or an input AliasOutput with the same AliasID.
296+
// - On alias state transitions:
297+
// - The StateIndex must be incremented by 1
298+
// - Only Amount, NativeTokens, StateIndex, StateMetadata and FoundryCounter can be mutated
299+
// - On alias governance transition:
300+
// - Only StateController (must be mutated), GovernanceController and the MetadataBlock can be mutated
301301
func (a *AliasOutput) ValidateStateTransition(transType ChainTransitionType, next ChainConstrainedOutput, semValCtx *SemanticValidationContext) error {
302302
var err error
303303
switch transType {

signature_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package iotago_test
33
import (
44
"encoding/json"
55
"errors"
6-
"io/ioutil"
6+
"os"
77
"path/filepath"
88
"testing"
99

@@ -45,7 +45,7 @@ func TestEd25519Signature_Valid(t *testing.T) {
4545
}
4646
var tests []test
4747
// load the tests from file
48-
b, err := ioutil.ReadFile(filepath.Join("testdata", t.Name()+".json"))
48+
b, err := os.ReadFile(filepath.Join("testdata", t.Name()+".json"))
4949
require.NoError(t, err)
5050
require.NoError(t, json.Unmarshal(b, &tests))
5151

transaction.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ func TxSemanticSTVFOnChains() TxSemanticValidationFunc {
701701
}
702702

703703
// TxSemanticNativeTokens validates following rules regarding NativeTokens:
704-
// - The NativeTokens between Inputs / Outputs must be balanced or have a deficit on the output side if
705-
// there is no foundry state transition for a given NativeToken.
706-
// - Max MaxNativeTokensCount native tokens within inputs + outputs
704+
// - The NativeTokens between Inputs / Outputs must be balanced or have a deficit on the output side if
705+
// there is no foundry state transition for a given NativeToken.
706+
// - Max MaxNativeTokensCount native tokens within inputs + outputs
707707
func TxSemanticNativeTokens() TxSemanticValidationFunc {
708708
return func(svCtx *SemanticValidationContext) error {
709709
// native token set creates handle overflows

unlock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ type ReferentialUnlock interface {
177177
type UnlockValidatorFunc func(index int, unlock Unlock) error
178178

179179
// UnlocksSigUniqueAndRefValidator returns a validator which checks that:
180-
// 1. SignatureUnlock(s) are unique
181-
// 2. ReferenceUnlock(s) reference a previous SignatureUnlock
180+
// 1. SignatureUnlock(s) are unique
181+
// 2. ReferenceUnlock(s) reference a previous SignatureUnlock
182182
// 3. Following through AliasUnlock(s), NFTUnlock(s) refs results to a SignatureUnlock
183183
func UnlocksSigUniqueAndRefValidator() UnlockValidatorFunc {
184184
seenSigUnlocks := map[uint16]struct{}{}

unlock_cond.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ func (f UnlockConditionSet) HasTimelockCondition() bool {
162162

163163
// tells whether the given ident can unlock an output containing this set of UnlockCondition(s)
164164
// when taking into consideration the constraints enforced by them:
165-
// - If the timelocks are not expired, then nobody can unlock.
166-
// - If the expiration blocks are expired, then only the return identity can unlock.
165+
// - If the timelocks are not expired, then nobody can unlock.
166+
// - If the expiration blocks are expired, then only the return identity can unlock.
167+
//
167168
// returns booleans indicating whether the given ident can unlock and whether the return identity can unlock.
168169
func (f UnlockConditionSet) unlockableBy(ident Address, extParas *ExternalUnlockParameters) (givenIdentCanUnlock bool, returnIdentCanUnlock bool) {
169170
if err := f.TimelocksExpired(extParas); err != nil {

0 commit comments

Comments
 (0)