Skip to content

Commit

Permalink
add_rpc_calls_fix_omni (#61)
Browse files Browse the repository at this point in the history
* add_rpc_calls_fix_omni

* wip

* fix zmq failing tests cpant

* wip

* tidy

* wip

* wip

* wip

* changes

* Release Net-Async-Blockchain 0.003

    [Improvements]
    - RPC call "getbalances" added as get_balances for Bitcoin
    - RPC call "omni_getwalletbalances" added as get_omni_wallet_balances for Omnicore
    [Breaking changes]
    - Omni get_transaction is now get_omni_transaction
    - Omni get_transaction now returns same as Bitcoin "gettransaction" RPC call

* version

---------

Co-authored-by: reginaldo-deriv <reginaldo@deriv.com>
  • Loading branch information
reginaldo-deriv and reginaldo-deriv committed Sep 18, 2023
1 parent d6bfbe8 commit 84146d1
Show file tree
Hide file tree
Showing 19 changed files with 514 additions and 83 deletions.
12 changes: 7 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ alias:
apt-get update
apt-get install -y --no-install-recommends ca-certificates git gcc libc6-dev libssl-dev libzmq3-dev zlib1g-dev
name: Install libraries and other packages
- &install_dzil
- &install_dzil
run:
command: |
cpm install -g --no-test Dist::Zilla Dist::Zilla::App::Command::cover ExtUtils::MakeMaker
name: Install Dzil
- &install_author_deps
run:
run:
name: Install dzil author dependencies
command: |
cpm install --no-test -g \
Expand All @@ -22,11 +22,11 @@ alias:
run:
name: Install dist deps
command: |
# see https://github.com/team-at-cpan/Dist-Zilla-Plugin-PodInherit/issues/1 to check why we not use
# see https://github.com/team-at-cpan/Dist-Zilla-Plugin-PodInherit/issues/1 to check why we not use
# dzil listdeps --missing directly here
cpanm -n --installdeps .
dzil listdeps --author --missing --cpanm-versions | xargs cpanm -n
jobs:
test:
parameters:
Expand Down Expand Up @@ -92,12 +92,14 @@ workflows:
- "5.30"
- "5.32"
- "5.34"
- "5.36"
- "5.38"
- release:
context: release-deriv
requires:
- test
filters:
branches:
only:
only:
- master
version: 2.1
13 changes: 9 additions & 4 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{{$NEXT}}

0.003 2023-09-12 17:08:09+00:00 UTC
[Improvements]
- RPC call "getbalances" added as get_balances for Bitcoin
- RPC call "omni_getwalletbalances" added as get_omni_wallet_balances for Omnicore
[Breaking changes]
- Omni get_transaction is now get_omni_transaction
- Omni get_transaction now returns same as Bitcoin "gettransaction" RPC call
0.002 2023-03-03 12:28:18+00:00 UTC
this release make is mandatory to send `jsonrpc` version as `2.0` as required by latest geth upgrade

this release make is mandatory to send `jsonrpc` version as `2.0` as required by latest geth upgrade
0.001 2022-11-24 12:28:18+00:00 UTC
Initial release

Initial release
379 changes: 379 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.024.
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.029.
use strict;
use warnings;

Expand All @@ -24,8 +24,6 @@ my %WriteMakefileArgs = (
"IO::Async::SSL" => 0,
"IO::Async::Timer::Periodic" => "0.72",
"JSON::MaybeUTF8" => "1.002",
"JSON::MaybeXS" => 0,
"Math::BigFloat" => "1.999814",
"Math::BigInt" => "1.999814",
"Net::Async::HTTP" => "0.43",
"Net::Async::WebSocket" => "0.13",
Expand Down Expand Up @@ -53,20 +51,17 @@ my %WriteMakefileArgs = (
"IPC::Open3" => 0,
"Net::Async::WebSocket::Server" => 0,
"Test::CheckDeps" => "0.010",
"Test::Exception" => 0,
"Test::Fatal" => 0,
"Test::MemoryGrowth" => 0,
"Test::MockModule" => 0,
"Test::More" => "0.98",
"Test::TCP" => 0
},
"VERSION" => "0.002",
"VERSION" => "0.003",
"test" => {
"TESTS" => "t/*.t"
}
);


my %FallbackPrereqs = (
"Digest::Keccak" => 0,
"ExtUtils::MakeMaker" => 0,
Expand All @@ -81,8 +76,6 @@ my %FallbackPrereqs = (
"IO::Handle" => 0,
"IPC::Open3" => 0,
"JSON::MaybeUTF8" => "1.002",
"JSON::MaybeXS" => 0,
"Math::BigFloat" => "1.999814",
"Math::BigInt" => "1.999814",
"Net::Async::HTTP" => "0.43",
"Net::Async::WebSocket" => "0.13",
Expand All @@ -93,9 +86,7 @@ my %FallbackPrereqs = (
"Socket" => 0,
"Syntax::Keyword::Try" => "0.09",
"Test::CheckDeps" => "0.010",
"Test::Exception" => 0,
"Test::Fatal" => 0,
"Test::MemoryGrowth" => 0,
"Test::MockModule" => 0,
"Test::More" => "0.98",
"Test::TCP" => 0,
Expand All @@ -110,7 +101,6 @@ my %FallbackPrereqs = (
"warnings" => 0
);


unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
Expand Down
5 changes: 1 addition & 4 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ requires 'perl', '5.024';
requires 'indirect', '>= 0.37';
requires 'Future::AsyncAwait', '>= 0.23';
requires 'IO::Async::SSL', 0;
requires 'JSON::MaybeXS', 0;
requires 'JSON::MaybeUTF8', '>= 1.002';
requires 'Digest::Keccak', 0;
requires 'Math::BigFloat', '>= 1.999814';
requires 'Math::BigInt', '>= 1.999814';
requires 'Net::Async::WebSocket', '>= 0.13';
requires 'Net::Async::HTTP', '>= 0.43';
Expand All @@ -17,8 +15,7 @@ requires 'IO::Async::Timer::Periodic', '>= 0.72';
on test => sub {
requires 'Test::More', '>= 0.98';
requires 'Test::MockModule', 0;
requires 'Test::MemoryGrowth', >= 0.03;
requires 'Test::Exception', 0;
requires 'Test::Fatal', 0;
};

on develop => sub {
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Async/Blockchain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Net::Async::Blockchain;
use strict;
use warnings;

our $VERSION = '0.002';
our $VERSION = '0.003';

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Async/Blockchain/BTC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Net::Async::Blockchain::BTC;
use strict;
use warnings;

our $VERSION = '0.002';
our $VERSION = '0.003';

=head1 NAME
Expand Down
9 changes: 6 additions & 3 deletions lib/Net/Async/Blockchain/Client/RPC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Net::Async::Blockchain::Client::RPC;
use strict;
use warnings;

our $VERSION = '0.002';
our $VERSION = '0.003';

=head1 NAME
Expand Down Expand Up @@ -127,7 +127,7 @@ Use any argument as the method parameter for the client RPC call
=back
L<Future>
L<Future> - node response as decoded json
=cut

Expand All @@ -139,9 +139,12 @@ async sub _request {
method => $method,
params => [@params],
};

# for Geth JSON-RPC spec requires the version field to be exactly "jsonrpc": "2.0"
$obj->{jsonrpc} = $self->jsonrpc if $self->jsonrpc;
$obj->{jsonrpc} = $self->jsonrpc if $self->can('jsonrpc');

my @post_params = ($self->endpoint, encode_json_utf8($obj), content_type => 'application/json');

# for ETH based, we don't require user+password. Check to send user+password if exists.
push @post_params, (user => $self->rpc_user) if $self->rpc_user;
push @post_params, (pass => $self->rpc_password) if $self->rpc_password;
Expand Down
85 changes: 69 additions & 16 deletions lib/Net/Async/Blockchain/Client/RPC/BTC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Net::Async::Blockchain::Client::RPC::BTC;
use strict;
use warnings;

our $VERSION = '0.002';
our $VERSION = '0.003';

=head1 NAME
Expand Down Expand Up @@ -33,17 +33,21 @@ no indirect;

use parent qw(Net::Async::Blockchain::Client::RPC);

sub jsonrpc { return undef }

=head2 get_transaction
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/wallet/gettransaction/
https://bitcoincore.org/en/doc/24.0.0/rpc/wallet/gettransaction/
=over 4
=item * C<txid> The transaction id
=item * C<include_watchonly> default=true for watch-only wallets, otherwise false
=item * C<verbose> Whether to include a `decoded` field containing the decoded transaction
=back
L<Future>
L<Future> - detailed information about in-wallet transaction C<txid>
=cut

Expand All @@ -56,13 +60,19 @@ use parent qw(Net::Async::Blockchain::Client::RPC);

=head2 get_raw_transaction
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/rawtransactions/getrawtransaction/
https://bitcoincore.org/en/doc/24.0.0/rpc/rawtransactions/getrawtransaction/
=over 4
=item * C<txid> The transaction id
=item * C<verbose> If false, return a string, otherwise return a json object
=item * C<blockhash> The block in which to look for the transaction
=back
L<Future>
L<Future> - raw transaction data
=cut

Expand All @@ -73,13 +83,17 @@ sub get_raw_transaction {

=head2 get_block
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/wallet/getblock/
https://bitcoincore.org/en/doc/24.0.0/rpc/wallet/getblock/
=over 4
=item * C<blockhash> the block hash
=item * C<verbosity> 0 for hex-encoded data, 1 for a JSON object, 2 for JSON object with transaction data, and 3 for JSON object with transaction data including prevout information for inputs
=back
L<Future>
L<Future> - string based in the verbosity value
=cut

Expand All @@ -90,13 +104,15 @@ sub get_block {

=head2 validate_address
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/util/validateaddress/
https://bitcoincore.org/en/doc/24.0.0/rpc/util/validateaddress/
=over 4
=item * C<address> - the bitcoin address to validate
=back
L<Future>
L<Future> - json {isvalid : true|false, ...}
=cut

Expand All @@ -107,13 +123,13 @@ sub validate_address {

=head2 get_last_block
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/blockchain/getblockcount/
https://bitcoincore.org/en/doc/24.0.0/rpc/blockchain/getblockcount/
=over 4
=back
L<Future>
L<Future> - The current block count
=cut

Expand All @@ -124,13 +140,15 @@ sub get_last_block {

=head2 get_block_hash
https://bitcoin-rpc.github.io/en/doc/0.17.99/rpc/blockchain/getblockhash/
https://bitcoincore.org/en/doc/24.0.0/rpc/blockchain/getblockhash/
=over 4
=item * C<height> the height index
=back
L<Future>
L<Future> - string block hash
=cut

Expand All @@ -139,5 +157,40 @@ sub get_block_hash {
return $self->_request('getblockhash', @params);
}

1;
=head2 list_by_addresses
https://bitcoincore.org/en/doc/24.0.0/rpc/wallet/listreceivedbyaddress/
=over 4
=item * C<address> address to return the received transactions
=back
L<Future> - json containing the received transaction details
=cut

sub list_by_addresses {
my ($self, $address) = @_;
return $self->_request("listreceivedbyaddress", 1, \0, \0, $address);
}

=head2 get_balances
https://bitcoincore.org/en/doc/24.0.0/rpc/wallet/getbalances/
=over 4
=back
L<Future> - json object with all balances in BTC
=cut

sub get_balances {
my ($self, @params) = @_;
return $self->_request('getbalances', @params);
}

1;
5 changes: 2 additions & 3 deletions lib/Net/Async/Blockchain/Client/RPC/ETH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Net::Async::Blockchain::Client::RPC::ETH;
use strict;
use warnings;

our $VERSION = '0.002';
our $VERSION = '0.003';

=head1 NAME
Expand Down Expand Up @@ -33,7 +33,7 @@ no indirect;

use parent qw(Net::Async::Blockchain::Client::RPC);

sub jsonrpc { return '2.0' }
sub jsonrpc { return '2.0' }

=head2 call
Expand Down Expand Up @@ -155,4 +155,3 @@ sub get_balance {
}

1;

Loading

0 comments on commit 84146d1

Please sign in to comment.