-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ciro S. Costa <[email protected]>
- Loading branch information
Showing
2 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/cirocosta/go-monero/pkg/daemonrpc" | ||
) | ||
|
||
type GetBlockTemplateCommand struct { | ||
WalletAddress string `long:"wallet-address" required:"true" description:"address of wallet to receive coinbase txns if block is successfully mined"` | ||
ReserveSize uint `long:"reserve-size" required:"true" description:"reserve size"` | ||
} | ||
|
||
func (c *GetBlockTemplateCommand) Execute(_ []string) error { | ||
client, err := daemonrpc.NewClient(options.Address, | ||
daemonrpc.WithHTTPClient(daemonrpc.NewHTTPClient(options.Verbose)), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("new client for '%s': %w", options.Address, err) | ||
} | ||
|
||
resp, err := client.GetBlockTemplate(c.WalletAddress, c.ReserveSize) | ||
if err != nil { | ||
return fmt.Errorf("get block count: %w", err) | ||
} | ||
|
||
encoder := json.NewEncoder(os.Stdout) | ||
encoder.SetIndent(" ", " ") | ||
|
||
if err := encoder.Encode(resp); err != nil { | ||
return fmt.Errorf("encode: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
parser.AddCommand("get-block-template", | ||
"Get a block template on which mining a new block", | ||
"Get a block template on which mining a new block", | ||
&GetBlockTemplateCommand{}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters