Skip to content

Commit

Permalink
- Renamed fields in indexer to match implementation and spec (#404)
Browse files Browse the repository at this point in the history
* - Renamed fields in indexer to match implementation and spec

* - Fixed reviewdog comments

* - gofmt all the things
  • Loading branch information
alexsporn authored Aug 9, 2022
1 parent 652becc commit ad22ee9
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 52 deletions.
11 changes: 6 additions & 5 deletions ms_opt_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions nodeclient/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
)
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions nodeclient/indexer_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions nodeclient/indexer_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
29 changes: 14 additions & 15 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions output_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package iotago_test
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand Down
5 changes: 3 additions & 2 deletions unlock_cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions unlock_cond_expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion unlock_cond_timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad22ee9

Please sign in to comment.