MCPcopy Create free account
hub / github.com/DNAProject/DNA / GetBlockData

Function GetBlockData

cmd/utils/gas.go:527–546  ·  view source on GitHub ↗
(hashOrHeight interface{})

Source from the content-addressed store, hash-verified

525}
526
527func GetBlockData(hashOrHeight interface{}) ([]byte, error) {
528 data, ontErr := sendRpcRequest("getblock", []interface{}{hashOrHeight})
529 if ontErr != nil {
530 switch ontErr.ErrorCode {
531 case ERROR_INVALID_PARAMS:
532 return nil, fmt.Errorf("invalid block hash or block height:%v", hashOrHeight)
533 }
534 return nil, ontErr.Error
535 }
536 hexStr := ""
537 err := json.Unmarshal(data, &hexStr)
538 if err != nil {
539 return nil, fmt.Errorf("json.Unmarshal error:%s", err)
540 }
541 blockData, err := hex.DecodeString(hexStr)
542 if err != nil {
543 return nil, fmt.Errorf("hex.DecodeString error:%s", err)
544 }
545 return blockData, nil
546}
547
548func GetBlockCount() (uint32, error) {
549 data, ontErr := sendRpcRequest("getblockcount", []interface{}{})

Callers 1

exportBlocksFunction · 0.92

Calls 2

sendRpcRequestFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected