github.com/gagliardetto/solana-go@v1.11.0/rpc/getBlockTime.go (about) 1 // Copyright 2021 github.com/gagliardetto 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rpc 16 17 import ( 18 "context" 19 20 "github.com/gagliardetto/solana-go" 21 ) 22 23 // GetBlockTime returns the estimated production time of a block. 24 // 25 // Each validator reports their UTC time to the ledger on a regular 26 // interval by intermittently adding a timestamp to a Vote for a 27 // particular block. A requested block's time is calculated from 28 // the stake-weighted mean of the Vote timestamps in a set of 29 // recent blocks recorded on the ledger. 30 // 31 // The result will be an int64 estimated production time, 32 // as Unix timestamp (seconds since the Unix epoch), 33 // or nil if the timestamp is not available for this block. 34 func (cl *Client) GetBlockTime( 35 ctx context.Context, 36 block uint64, // block, identified by Slot 37 ) (out *solana.UnixTimeSeconds, err error) { 38 params := []interface{}{block} 39 err = cl.rpcClient.CallForInto(ctx, &out, "getBlockTime", params) 40 return 41 }