From 0e4487db242d41c37200109fb6e2a45c4c9f0417 Mon Sep 17 00:00:00 2001
From: Arpit Temani <temaniarpit27@gmail.com>
Date: Tue, 29 Sep 2020 13:06:23 +0530
Subject: [PATCH] add: bor author api

---
 consensus/bor/api.go        | 17 +++++++++++++++++
 internal/web3ext/web3ext.go |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/consensus/bor/api.go b/consensus/bor/api.go
index 5af1ddbc3..9af5042db 100644
--- a/consensus/bor/api.go
+++ b/consensus/bor/api.go
@@ -62,6 +62,23 @@ func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error) {
 	return api.bor.snapshot(api.chain, header.Number.Uint64(), header.Hash(), nil)
 }
 
+// GetAuthor retrieves the author a block.
+func (api *API) GetAuthor(number *rpc.BlockNumber) (*common.Address, error) {
+	// Retrieve the requested block number (or current if none requested)
+	var header *types.Header
+	if number == nil || *number == rpc.LatestBlockNumber {
+		header = api.chain.CurrentHeader()
+	} else {
+		header = api.chain.GetHeaderByNumber(uint64(number.Int64()))
+	}
+	// Ensure we have an actually valid block and return its snapshot
+	if header == nil {
+		return nil, errUnknownBlock
+	}
+	author, err := api.bor.Author(header)
+	return &author, err
+}
+
 // GetSnapshotAtHash retrieves the state snapshot at a given block.
 func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error) {
 	header := api.chain.GetHeaderByHash(hash)
diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go
index 326b5cc4c..2c022d34d 100644
--- a/internal/web3ext/web3ext.go
+++ b/internal/web3ext/web3ext.go
@@ -129,6 +129,12 @@ web3._extend({
 			params: 1,
 			inputFormatter: [null]
 		}),
+		new web3._extend.Method({
+			name: 'getAuthor',
+			call: 'bor_getAuthor',
+			params: 1,
+			inputFormatter: [null]
+		}),
 		new web3._extend.Method({
 			name: 'getSnapshotAtHash',
 			call: 'bor_getSnapshotAtHash',
-- 
GitLab