github.com/iotexproject/iotex-core@v1.14.1-rc1/blockindex/contractstaking/bucket.go (about) 1 // Copyright (c) 2023 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package contractstaking 7 8 import ( 9 "time" 10 11 "github.com/iotexproject/iotex-core/action/protocol/staking" 12 ) 13 14 // Bucket defines the bucket struct for contract staking 15 type Bucket = staking.VoteBucket 16 17 func assembleBucket(token uint64, bi *bucketInfo, bt *BucketType, contractAddr string, blockInterval time.Duration) *Bucket { 18 vb := Bucket{ 19 Index: token, 20 StakedAmount: bt.Amount, 21 StakedDuration: time.Duration(bt.Duration) * blockInterval, 22 StakedDurationBlockNumber: bt.Duration, 23 CreateBlockHeight: bi.CreatedAt, 24 StakeStartBlockHeight: bi.CreatedAt, 25 UnstakeStartBlockHeight: bi.UnstakedAt, 26 AutoStake: bi.UnlockedAt == maxBlockNumber, 27 Candidate: bi.Delegate, 28 Owner: bi.Owner, 29 ContractAddress: contractAddr, 30 } 31 if bi.UnlockedAt != maxBlockNumber { 32 vb.StakeStartBlockHeight = bi.UnlockedAt 33 } 34 return &vb 35 }