#!/usr/bin/env perl

=head1 NAME

rlp

=head1 SYNOPSIS

rlp [options] [params]

Options:

    --action=encode/decode (required)

Example:

Encoding:

    rlp --action=encode 0x9 0x4a817c800 0x5208 0x3535353535353535353535353535353535353535 0xde0b6b3a7640000 0x 0x1 0x 0x

Decoding:

    rlp --action=decode ec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080

=head1 DESCRIPTION

Standalone version for decoding and encoding RLP

=cut

use strict;
use warnings;

use Carp;
use Getopt::Long;
use Pod::Usage;

use Blockchain::Ethereum::RLP;

my $action;
GetOptions("action=s" => \$action);

my $ref = __PACKAGE__->can($action);
pod2usage(1) unless $action && $ref;

# croak <<USAGE
# Action is missing, you need to specify decode or encode ex.:

# Encoding:
# \$ rlp encode 0x9 0x4a817c800 0x5208 0x3535353535353535353535353535353535353535 0xde0b6b3a7640000 0x 0x1 0x 0x

# Decoding:
# \$ rlp decode ec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080

# USAGE
# unless $action and __PACKAGE__->can($action);

my $rlp = Blockchain::Ethereum::RLP->new;

sub decode {
    printf("%s\n", join(", ", $rlp->decode(pack "H*", shift @ARGV)->@*));
}

sub encode {
    printf("%s\n", unpack "H*", $rlp->encode(\@ARGV));
}

&$ref;
