NAME
Circle::Miner - The miner module for circle chain sdk.
VERSION
Version 0.01
SYNOPSIS
Circle::Miner example:
use Circle::Miner;
use JSON;
my $miner = Circle::Miner->new();
my $address = '<your address>';
my $result = $miner->fetch_my_block($address);
if ($result->{status} == 200) {
my $block_header = $result->{blockHeaderHexString};
my $ip_port = $result->{ipPort};
my $mined_block = $miner->mine_block($block_header, 2);
my $result = $miner->post_my_block($address, $mined_block, $ip_port);
print "post my block result:" . encode_json($result);
}
...
EXPORT
there are 4 methods for the Circle::Miner module.
new
fetch_my_block
mine_block
post_my_block
SUBROUTINES/METHODS
new
Creates a new Circle::Miner object instance.
Parameters: None
Returns: A new Circle::Miner object instance
Example: my $miner = Circle::Miner->new();
fetch_my_block($address)
Fetches a block for mining based on the provided wallet address.
Parameters:
$address - A string representing the wallet address (required)
Returns: A hashref containing:
status: HTTP status code
data: the data of return
data.blockHeaderHexString: The block header in hex format
data.ipPort: The IP and port of the node
Throws:
Croaks if address is not provided
Example:
my $result = $miner->fetch_my_block('1ABC...');
if ($result->{status} == 200) {
# Process the block header
}
mine_block($header_hex, $thread_count)
Mines a block using the provided block header hex string with multi-threading support.
Parameters:
$header_hex - A hex string representing the block header (required)
$thread_count - Number of threads to use for mining (optional, defaults to 1)
Returns: The mined block data read from './mined.txt'
Throws: Croaks if header_hex is not provided or invalid
Example:
my $mined_block = $miner->mine_block($block_header, 2);
Notes:
Spawns multiple processes based on thread_count
Each process mines a different nonce range
When first process finds solution, others are terminated
Uses external mining executable (ccm) based on OS/architecture
post_my_block($address, $header_hex, $ip_port)
Posts a mined block to the network.
Parameters:
$address - The wallet address (required, must be 34 chars and start with '1')
$header_hex - The mined block header in hex format (required)
$ip_port - The IP and port of the node to post to (required)
Returns:
status: HTTP status code
data: Response data from the server
Throws: Croaks if:
Any required parameter is missing
Address format is invalid (length != 34 or doesn't start with '1')
Example:
my $result = $miner->post_my_block('1ABC...', $mined_block, '127.0.0.1:8080');
if ($result->{status} == 200) {
# Block successfully posted
}
AUTHOR
charles li, <lidh04 at gmail.com>
BUGS
Please report any bugs or feature requests to bug-circle-miner at rt.cpan.org
, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Circle-Miner. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Circle::Miner
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2024 by charles li.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)