add docs for contrac records query
@@ -2,11 +2,15 @@ package hedera
import "github.com/hashgraph/hedera-sdk-go/proto"
+// ContractRecordsQuery retrieves all of the records for a smart contract instance, for any function call
+// (or the constructor call) during the last 25 hours, for which a Record was requested.
type ContractRecordsQuery struct {
QueryBuilder
pb *proto.ContractGetRecordsQuery
}
+// NewContractRecordsQuery creates a ContractRecordsQuery builder which can be used to construct and execute a
+// Contract Get Records Query
func NewContractRecordsQuery() *ContractRecordsQuery {
pb := &proto.ContractGetRecordsQuery{Header: &proto.QueryHeader{}}
@@ -16,21 +20,24 @@ func NewContractRecordsQuery() *ContractRecordsQuery {
return &ContractRecordsQuery{inner, pb}
}
+// SetContractID sets the smart contract instance for which the records should be retrieved
func (builder *ContractRecordsQuery) SetContractID(id ContractID) *ContractRecordsQuery {
builder.pb.ContractID = id.toProto()
return builder
}
+// Execute executes the ContractRecordsQuery using the provided client.
func (builder *ContractRecordsQuery) Execute(client *Client) ([]TransactionRecord, error) {
- var records = []TransactionRecord{}
-
resp, err := builder.execute(client)
if err != nil {
- return records, err
+ return nil, err
}
- for _, element := range resp.GetContractGetRecordsResponse().Records {
- records = append(records, transactionRecordFromProto(element))
+ rawRecords := resp.GetContractGetRecordsResponse().Records
+ records := make([]TransactionRecord, len(rawRecords))
+
+ for i, element := range resp.GetContractGetRecordsResponse().Records {
+ records[i] = transactionRecordFromProto(element)
}
return records, nil
