Skip to content

Commit

Permalink
Add ImplicitAccountCreationParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Sep 22, 2023
1 parent e1a2d45 commit e8eddac
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type ProtocolParameters interface {

RewardsParameters() *RewardsParameters

ImplicitAccountCreationParameters() *ImplicitAccountCreationParameters

Bytes() ([]byte, error)

Hash() (Identifier, error)
Expand Down
5 changes: 4 additions & 1 deletion api_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ 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 @@ -74,5 +76,6 @@ 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.RewardsParameters.Equals(other.RewardsParameters) &&
b.ImplicitAccountCreationParameters.Equals(other.ImplicitAccountCreationParameters)
}
3 changes: 2 additions & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ 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,"bootstrappinDuration":"1154","manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31}}`
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,"bootstrappinDuration":"1154","manaShareCoefficient":"2","decayBalancingConstantExponent":8,"decayBalancingConstant":"1","poolCoefficientExponent":31},"implicitAccountCreationParameters":{"onboardingReferenceManaCost":"1500"}}`

jsonProtoParams, err := tpkg.TestAPI.JSONEncode(protoParams)
require.NoError(t, err)
Expand Down
15 changes: 13 additions & 2 deletions api_v3_protocol_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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 @@ -123,6 +124,10 @@ 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 @@ -137,8 +142,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",
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)
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)
}

func (p *V3ProtocolParameters) ManaDecayProvider() *ManaDecayProvider {
Expand Down Expand Up @@ -285,3 +290,9 @@ 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
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions implicit_account_creation_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package iotago

type ImplicitAccountCreationParameters struct {
// OnboardingReferenceManaCost is the value of the reference Mana cost used to prefund a BasicOutput on an ImplicitAccountCreationAddress.
OnboardingReferenceManaCost Mana `serix:"0,mapKey=onboardingReferenceManaCost"`
}

func (c *ImplicitAccountCreationParameters) Equals(other ImplicitAccountCreationParameters) bool {
return c.OnboardingReferenceManaCost == other.OnboardingReferenceManaCost
}
Loading

0 comments on commit e8eddac

Please sign in to comment.