Skip to content

Commit

Permalink
Merge branch 'serix-iota-core' of github.com:iotaledger/iota.go into …
Browse files Browse the repository at this point in the history
…feat/transaction-id-with-creation-slot
  • Loading branch information
muXxer committed Sep 25, 2023
2 parents f90fcc0 + b15e39b commit 76cc245
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 198 deletions.
2 changes: 0 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ type ProtocolParameters interface {

RewardsParameters() *RewardsParameters

ImplicitAccountCreationParameters() *ImplicitAccountCreationParameters

Bytes() ([]byte, error)

Hash() (Identifier, error)
Expand Down
5 changes: 1 addition & 4 deletions api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ type basicProtocolParameters struct {
VersionSignaling VersionSignaling `serix:"18,mapKey=versionSignaling"`
// RewardsParameters defines the parameters used for reward calculation.
RewardsParameters RewardsParameters `serix:"19,mapKey=rewardsParameters"`
// ImplicitAccountCreationParameters defines the parameters used for implicit account creation.
ImplicitAccountCreationParameters ImplicitAccountCreationParameters `serix:"20,mapKey=implicitAccountCreationParameters"`
}

func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
Expand All @@ -76,6 +74,5 @@ func (b basicProtocolParameters) Equals(other basicProtocolParameters) bool {
b.EpochNearingThreshold == other.EpochNearingThreshold &&
b.CongestionControlParameters.Equals(other.CongestionControlParameters) &&
b.VersionSignaling.Equals(other.VersionSignaling) &&
b.RewardsParameters.Equals(other.RewardsParameters) &&
b.ImplicitAccountCreationParameters.Equals(other.ImplicitAccountCreationParameters)
b.RewardsParameters.Equals(other.RewardsParameters)
}
3 changes: 1 addition & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ func TestProtocolParametersJSONMarshalling(t *testing.T) {
),
iotago.WithVersionSignalingOptions(3, 4, 1),
iotago.WithRewardsOptions(10, 8, 8, 31, 1154, 2, 1),
iotago.WithImplicitAccountCreationOptions(1500),
)

protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentStructure":{"vByteCost":6,"vByteFactorData":7,"vByteFactorKey":8,"vByteFactorBlockIssuerKey":9,"vByteFactorStakingFeature":10,"vByteFactorDelegation":10},"workScoreStructure":{"dataByte":1,"block":2,"missingParent":3,"input":4,"contextInput":5,"output":6,"nativeToken":7,"staking":8,"blockIssuer":9,"allotment":10,"signatureEd25519":11,"minStrongParentsThreshold":12},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":1,"generationRate":1,"generationRateExponent":27,"decayFactors":[10,20],"decayFactorsExponent":32,"decayFactorEpochsSum":1337,"decayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":11,"validationBlocksPerSlot":10,"punishmentEpochs":9,"livenessThreshold":3,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"minMana":"1","maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1},"rewardsParameters":{"validatorBlocksPerSlot":10,"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31},"implicitAccountCreationParameters":{"onboardingReferenceManaCost":"1500"}}`
protoParamsJSON := `{"type":0,"version":3,"networkName":"xxxNetwork","bech32Hrp":"xxx","rentStructure":{"vByteCost":6,"vByteFactorData":7,"vByteFactorKey":8,"vByteFactorBlockIssuerKey":9,"vByteFactorStakingFeature":10,"vByteFactorDelegation":10},"workScoreStructure":{"dataByte":1,"block":2,"missingParent":3,"input":4,"contextInput":5,"output":6,"nativeToken":7,"staking":8,"blockIssuer":9,"allotment":10,"signatureEd25519":11,"minStrongParentsThreshold":12},"tokenSupply":"1234567890987654321","genesisUnixTimestamp":"1681373293","slotDurationInSeconds":10,"slotsPerEpochExponent":13,"manaStructure":{"bitsCount":1,"generationRate":1,"generationRateExponent":27,"decayFactors":[10,20],"decayFactorsExponent":32,"decayFactorEpochsSum":1337,"decayFactorEpochsSumExponent":20},"stakingUnbondingPeriod":11,"validationBlocksPerSlot":10,"punishmentEpochs":9,"livenessThreshold":3,"minCommittableAge":10,"maxCommittableAge":20,"epochNearingThreshold":24,"congestionControlParameters":{"minReferenceManaCost":"500","increase":"500","decrease":"500","increaseThreshold":800000,"decreaseThreshold":500000,"schedulerRate":100000,"minMana":"1","maxBufferSize":1000,"maxValidationBufferSize":100},"versionSignaling":{"windowSize":3,"windowTargetRatio":4,"activationOffset":1},"rewardsParameters":{"validatorBlocksPerSlot":10,"profitMarginExponent":8,"bootstrappingDuration":1154,"manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
15 changes: 2 additions & 13 deletions api_v3_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func NewV3ProtocolParameters(opts ...options.Option[V3ProtocolParameters]) *V3Pr
WithStakingOptions(10, 10, 10),
WithVersionSignalingOptions(7, 5, 7),
WithRewardsOptions(10, 8, 8, 31, 1154, 2, 1),
WithImplicitAccountCreationOptions(5),
},
opts...,
),
Expand Down Expand Up @@ -124,10 +123,6 @@ func (p *V3ProtocolParameters) RewardsParameters() *RewardsParameters {
return &p.basicProtocolParameters.RewardsParameters
}

func (p *V3ProtocolParameters) ImplicitAccountCreationParameters() *ImplicitAccountCreationParameters {
return &p.basicProtocolParameters.ImplicitAccountCreationParameters
}

func (p *V3ProtocolParameters) Bytes() ([]byte, error) {
return CommonSerixAPI().Encode(context.TODO(), p)
}
Expand All @@ -142,8 +137,8 @@ func (p *V3ProtocolParameters) Hash() (Identifier, error) {
}

func (p *V3ProtocolParameters) String() string {
return fmt.Sprintf("ProtocolParameters: {\n\tVersion: %d\n\tNetwork Name: %s\n\tBech32 HRP Prefix: %s\n\tRent Structure: %v\n\tWorkScore Structure: %v\n\tToken Supply: %d\n\tGenesis Unix Timestamp: %d\n\tSlot Duration in Seconds: %d\n\tSlots per Epoch Exponent: %d\n\tMana Structure: %v\n\tStaking Unbonding Period: %d\n\tValidation Blocks per Slot: %d\n\tPunishment Epochs: %d\n\tLiveness Threshold: %d\n\tMin Committable Age: %d\n\tMax Committable Age: %d\n\tEpoch Nearing Threshold: %d\n\tCongestion Control parameters: %v\n\tVersion Signaling: %v\n\tRewardsParameters: %v\n\tImplicitAccountCreationParameters: %v\n",
p.basicProtocolParameters.Version, p.basicProtocolParameters.NetworkName, p.basicProtocolParameters.Bech32HRP, p.basicProtocolParameters.RentStructure, p.basicProtocolParameters.WorkScoreStructure, p.basicProtocolParameters.TokenSupply, p.basicProtocolParameters.GenesisUnixTimestamp, p.basicProtocolParameters.SlotDurationInSeconds, p.basicProtocolParameters.SlotsPerEpochExponent, p.basicProtocolParameters.ManaStructure, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.PunishmentEpochs, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge, p.basicProtocolParameters.EpochNearingThreshold, p.basicProtocolParameters.CongestionControlParameters, p.basicProtocolParameters.VersionSignaling, p.basicProtocolParameters.RewardsParameters, p.basicProtocolParameters.ImplicitAccountCreationParameters)
return fmt.Sprintf("ProtocolParameters: {\n\tVersion: %d\n\tNetwork Name: %s\n\tBech32 HRP Prefix: %s\n\tRent Structure: %v\n\tWorkScore Structure: %v\n\tToken Supply: %d\n\tGenesis Unix Timestamp: %d\n\tSlot Duration in Seconds: %d\n\tSlots per Epoch Exponent: %d\n\tMana Structure: %v\n\tStaking Unbonding Period: %d\n\tValidation Blocks per Slot: %d\n\tPunishment Epochs: %d\n\tLiveness Threshold: %d\n\tMin Committable Age: %d\n\tMax Committable Age: %d\n\tEpoch Nearing Threshold: %d\n\tCongestion Control parameters: %v\n\tVersion Signaling: %v\n\tRewardsParameters: %v\n",
p.basicProtocolParameters.Version, p.basicProtocolParameters.NetworkName, p.basicProtocolParameters.Bech32HRP, p.basicProtocolParameters.RentStructure, p.basicProtocolParameters.WorkScoreStructure, p.basicProtocolParameters.TokenSupply, p.basicProtocolParameters.GenesisUnixTimestamp, p.basicProtocolParameters.SlotDurationInSeconds, p.basicProtocolParameters.SlotsPerEpochExponent, p.basicProtocolParameters.ManaStructure, p.basicProtocolParameters.StakingUnbondingPeriod, p.basicProtocolParameters.ValidationBlocksPerSlot, p.basicProtocolParameters.PunishmentEpochs, p.basicProtocolParameters.LivenessThreshold, p.basicProtocolParameters.MinCommittableAge, p.basicProtocolParameters.MaxCommittableAge, p.basicProtocolParameters.EpochNearingThreshold, p.basicProtocolParameters.CongestionControlParameters, p.basicProtocolParameters.VersionSignaling, p.basicProtocolParameters.RewardsParameters)
}

func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider {
Expand Down Expand Up @@ -290,9 +285,3 @@ func WithRewardsOptions(validatorBlocksPerSlot, profitMarginExponent, decayBalan
p.basicProtocolParameters.RewardsParameters.PoolCoefficientExponent = poolCoefficientExponent
}
}

func WithImplicitAccountCreationOptions(onboardingReferenceManaCost Mana) options.Option[V3ProtocolParameters] {
return func(p *V3ProtocolParameters) {
p.basicProtocolParameters.ImplicitAccountCreationParameters.OnboardingReferenceManaCost = onboardingReferenceManaCost
}
}
14 changes: 7 additions & 7 deletions builder/output_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,14 @@ func (builder *NFTOutputBuilder) Build() (*iotago.NFTOutput, error) {
}

// NewDelegationOutputBuilder creates a new DelegationOutputBuilder with the account address, serial number, token scheme and base token amount.
func NewDelegationOutputBuilder(validatorID iotago.AccountID, addr iotago.Address, amount iotago.BaseToken) *DelegationOutputBuilder {
func NewDelegationOutputBuilder(validatorAddress *iotago.AccountAddress, addr iotago.Address, amount iotago.BaseToken) *DelegationOutputBuilder {
return &DelegationOutputBuilder{output: &iotago.DelegationOutput{
Amount: amount,
DelegatedAmount: 0,
DelegationID: iotago.DelegationID{},
ValidatorID: validatorID,
StartEpoch: 0,
EndEpoch: 0,
Amount: amount,
DelegatedAmount: 0,
DelegationID: iotago.DelegationID{},
ValidatorAddress: validatorAddress,
StartEpoch: 0,
EndEpoch: 0,
Conditions: iotago.DelegationOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: addr},
},
Expand Down
38 changes: 19 additions & 19 deletions builder/output_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,27 @@ func TestAccountOutputBuilder(t *testing.T) {

func TestDelegationOutputBuilder(t *testing.T) {
var (
address = tpkg.RandEd25519Address()
updatedAddress = tpkg.RandEd25519Address()
amount iotago.BaseToken = 1337
updatedAmount iotago.BaseToken = 127
validatorID = tpkg.RandAccountID()
delegationID = tpkg.RandDelegationID()
address = tpkg.RandEd25519Address()
updatedAddress = tpkg.RandEd25519Address()
amount iotago.BaseToken = 1337
updatedAmount iotago.BaseToken = 127
validatorAddress = tpkg.RandAccountAddress()
delegationID = tpkg.RandDelegationID()
)

delegationOutput, err := builder.NewDelegationOutputBuilder(validatorID, address, amount).
delegationOutput, err := builder.NewDelegationOutputBuilder(validatorAddress, address, amount).
DelegatedAmount(amount).
StartEpoch(1000).
Build()
require.NoError(t, err)

expected := &iotago.DelegationOutput{
Amount: 1337,
DelegatedAmount: 1337,
DelegationID: iotago.EmptyDelegationID(),
ValidatorID: validatorID,
StartEpoch: 1000,
EndEpoch: 0,
Amount: 1337,
DelegatedAmount: 1337,
DelegationID: iotago.EmptyDelegationID(),
ValidatorAddress: validatorAddress,
StartEpoch: 1000,
EndEpoch: 0,
Conditions: iotago.DelegationOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: address},
},
Expand All @@ -204,12 +204,12 @@ func TestDelegationOutputBuilder(t *testing.T) {
require.NoError(t, err)

expectedOutput := &iotago.DelegationOutput{
Amount: 127,
DelegatedAmount: 127,
ValidatorID: validatorID,
DelegationID: delegationID,
StartEpoch: 1000,
EndEpoch: 1500,
Amount: 127,
DelegatedAmount: 127,
ValidatorAddress: validatorAddress,
DelegationID: delegationID,
StartEpoch: 1000,
EndEpoch: 1500,
Conditions: iotago.DelegationOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: updatedAddress},
},
Expand Down
10 changes: 0 additions & 10 deletions implicit_account_creation_params.go

This file was deleted.

Loading

0 comments on commit 76cc245

Please sign in to comment.