Implemented neofs-go, neo-go, neofs-authmate lib

This commit is contained in:
Vladimir Avdeev 2022-09-19 20:00:46 +03:00 committed by Vladimir Avdeev
parent d3e5ee2231
commit c48f7b7ff2
25 changed files with 2306 additions and 0 deletions

2
cli/go/__init__.py Normal file
View file

@ -0,0 +1,2 @@
from .blockchain_network_type import NetworkType
from .go import NeoGo

View file

@ -0,0 +1,7 @@
from enum import Enum
class NetworkType(Enum):
PRIVATE = "privnet"
MAIN = "mainnet"
TEST = "testnet"

120
cli/go/candidate.py Normal file
View file

@ -0,0 +1,120 @@
from typing import Optional
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
class NeoGoCandidate(NeofsCliCommand):
def register(
self,
address: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
gas: Optional[float] = None,
timeout: int = 10,
) -> CommandResult:
""" register as a new candidate
Args:
address (str): Address to register
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
gas (float): network fee to add to the transaction (prioritizing it)
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet candidate register",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def unregister(
self,
address: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
gas: Optional[float] = None,
timeout: int = 10,
) -> CommandResult:
""" unregister self as a candidate
Args:
address (str): Address to unregister
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
gas (float): network fee to add to the transaction (prioritizing it)
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet candidate unregister",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def vote(
self,
candidate: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
gas: Optional[float] = None,
timeout: int = 10,
) -> CommandResult:
""" Votes for a validator by calling "vote" method of a NEO native
contract. Do not provide candidate argument to perform unvoting.
Args:
candidate (str): Public key of candidate to vote for
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
gas (float): network fee to add to the transaction (prioritizing it)
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet candidate vote",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)

358
cli/go/contract.py Normal file
View file

@ -0,0 +1,358 @@
from typing import Optional
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
class NeoGoContract(NeofsCliCommand):
def compile(
self,
input_file: str,
out: str,
manifest: str,
config: str,
no_standards: bool = False,
no_events: bool = False,
no_permissions: bool = False,
bindings: Optional[str] = None,
) -> CommandResult:
"""compile a smart contract to a .nef file
Args:
input_file (str): Input file for the smart contract to be compiled
out (str): Output of the compiled contract
manifest (str): Emit contract manifest (*.manifest.json) file into separate
file using configuration input file (*.yml)
config (str): Configuration input file (*.yml)
no_standards (bool): do not check compliance with supported standards
no_events (bool): do not check emitted events with the manifest
no_permissions (bool): do not check if invoked contracts are allowed in manifest
bindings (str): output file for smart-contract bindings configuration
Returns:
str: Command string
"""
return self._execute(
"contract compile",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def deploy(
self,
address: str,
input_file: str,
sysgas: float,
manifest: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
gas: Optional[float] = None,
out: Optional[str] = None,
force: bool = False,
timeout: int = 10,
) -> CommandResult:
"""deploy a smart contract (.nef with description)
Args:
wallet (str): wallet to use to get the key for transaction signing;
conflicts with wallet_config
wallet_config (str): path to wallet config to use to get the key for transaction
signing; conflicts with wallet
address (str): address to use as transaction signee (and gas source)
gas (float): network fee to add to the transaction (prioritizing it)
sysgas (float): system fee to add to transaction (compensating for execution)
out (str): file to put JSON transaction to
force (bool): Do not ask for a confirmation
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
input_file (str): Input file for the smart contract (*.nef)
manifest (str): Emit contract manifest (*.manifest.json) file into separate
file using configuration input file (*.yml)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"contract deploy",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def generate_wrapper(
self,
out: str,
hash: str,
config: Optional[str] = None,
manifest: Optional[str] = None,
) -> CommandResult:
"""generate wrapper to use in other contracts
Args:
config (str): Configuration file to use
manifest (str): Read contract manifest (*.manifest.json) file
out (str): Output of the compiled contract
hash (str): Smart-contract hash
Returns:
str: Command string
"""
return self._execute(
"contract generate-wrapper",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def invokefunction(
self,
address: str,
scripthash: str,
wallet: Optional[str] = None,
method: Optional[str] = None,
arguments: Optional[str] = None,
multisig_hash: Optional[str] = None,
wallet_config: Optional[str] = None,
gas: Optional[float] = None,
sysgas: Optional[float] = None,
out: Optional[str] = None,
force: bool = False,
rpc_endpoint: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""Executes given (as a script hash) deployed script with the given method,
arguments and signers. Sender is included in the list of signers by default
with None witness scope. If you'd like to change default sender's scope,
specify it via signers parameter. See testinvokefunction documentation for
the details about parameters. It differs from testinvokefunction in that this
command sends an invocation transaction to the network.
Args:
scripthash (str): Function hash
method (str): Call method
arguments (str): Method arguments
multisig_hash (str): Multisig hash
wallet (str): wallet to use to get the key for transaction signing;
conflicts with wallet_config
wallet_config (str): path to wallet config to use to get the key for transaction
signing; conflicts with wallet
address (str): address to use as transaction signee (and gas source)
gas (float): network fee to add to the transaction (prioritizing it)
sysgas (float): system fee to add to transaction (compensating for execution)
out (str): file to put JSON transaction to
force (bool): force-push the transaction in case of bad VM state after
test script invocation
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
multisig_hash = f"-- {multisig_hash}" or ""
return self._execute(
"contract invokefunction "
f"{scripthash} {method or ''} {arguments or ''} {multisig_hash}",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self", "scripthash", "method", "arguments", "multisig_hash"]
},
)
def testinvokefunction(
self,
scripthash: str,
wallet: Optional[str] = None,
method: Optional[str] = None,
arguments: Optional[str] = None,
multisig_hash: Optional[str] = None,
rpc_endpoint: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""Executes given (as a script hash) deployed script with the given method,
arguments and signers (sender is not included by default). If no method is given
"" is passed to the script, if no arguments are given, an empty array is
passed, if no signers are given no array is passed. If signers are specified,
the first one of them is treated as a sender. All of the given arguments are
encapsulated into array before invoking the script. The script thus should
follow the regular convention of smart contract arguments (method string and
an array of other arguments).
See more information and samples in `neo-go contract testinvokefunction --help`
Args:
scripthash (str): Function hash
method (str): Call method
arguments (str): Method arguments
multisig_hash (str): Multisig hash
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
multisig_hash = f"-- {multisig_hash}" or ""
return self._execute(
"contract testinvokefunction "
f"{scripthash} {method or ''} {arguments or ''} {multisig_hash}",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self", "scripthash", "method", "arguments", "multisig_hash"]
},
)
def testinvokescript(
self,
input_file: str,
rpc_endpoint: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""Executes given compiled AVM instructions in NEF format with the given set of
signers not included sender by default. See testinvokefunction documentation
for the details about parameters.
Args:
input_file (str): Input location of the .nef file that needs to be invoked
conflicts with wallet_config
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
return self._execute(
f"contract testinvokescript",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def init(
self,
name: str,
skip_details: bool = False,
) -> CommandResult:
"""initialize a new smart-contract in a directory with boiler plate code
Args:
name (str): name of the smart-contract to be initialized
skip_details (bool): skip filling in the projects and contract details
Returns:
str: Command string
"""
return self._execute(
"contract init",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def inspect(
self,
input_file: Optional[str] = None,
compile: Optional[str] = None,
) -> CommandResult:
"""creates a user readable dump of the program instructions
Args:
input_file (str): input file of the program (either .go or .nef)
compile (str): compile input file (it should be go code then)
Returns:
str: Command string
"""
return self._execute(
"contract inspect",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def calc_hash(
self,
input_file: str,
manifest: str,
sender: Optional[str] = None,
) -> CommandResult:
"""calculates hash of a contract after deployment
Args:
input_file (str): path to NEF file
sender (str): sender script hash or address
manifest (str): path to manifest file
Returns:
str: Command string
"""
return self._execute(
"contract calc-hash",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def add_group(
self,
manifest: str,
address: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
sender: Optional[str] = None,
nef: Optional[str] = None,
) -> CommandResult:
"""adds group to the manifest
Args:
wallet (str): wallet to use to get the key for transaction signing;
conflicts with wallet_config
wallet_config (str): path to wallet config to use to get the key for transaction
signing; conflicts with wallet
sender (str): deploy transaction sender
address (str): account to sign group with
nef (str): path to the NEF file
manifest (str): path to the manifest
Returns:
str: Command string
"""
return self._execute(
"contract manifest add-group",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)

74
cli/go/db.py Normal file
View file

@ -0,0 +1,74 @@
from typing import Optional
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
from .blockchain_network_type import NetworkType
class NeoGoDb(NeofsCliCommand):
def dump(
self,
config_path: str,
out: str,
network: NetworkType = NetworkType.PRIVATE,
count: int = 0,
start: int = 0,
) -> CommandResult:
""" dump blocks (starting with block #1) to the file
Args:
config_path (str): path to config
network (NetworkType): Select network type (default: private)
count (int): number of blocks to be processed (default or 0: all chain)
(default: 0)
start (int): block number to start from (default: 0) (default: 0)
out (srt): Output file (stdout if not given)
Returns:
str: Command string
"""
return self._execute(
"db dump",
**{network.value: True},
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def restore(
self,
config_path: str,
input_file: str,
network: NetworkType = NetworkType.PRIVATE,
count: int = 0,
dump: Optional[str] = None,
incremental: bool = False,
) -> CommandResult:
""" dump blocks (starting with block #1) to the file
Args:
config_path (str): path to config
network (NetworkType): Select network type (default: private)
count (int): number of blocks to be processed (default or 0: all chain)
(default: 0)
input_file (str): Input file (stdin if not given)
dump (str): directory for storing JSON dumps
incremental (bool): use if dump is incremental
Returns:
str: Command string
"""
return self._execute(
"db restore",
**{network.value: True},
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)

44
cli/go/go.py Normal file
View file

@ -0,0 +1,44 @@
from typing import Optional
from shell import Shell
from .candidate import NeoGoCandidate
from .contract import NeoGoContract
from .db import NeoGoDb
from .nep17 import NeoGoNep17
from .node import NeoGoNode
from .query import NeoGoQuery
from .version import NeoGoVersion
from .wallet import NeoGoWallet
class NeoGo:
neo_go_exec_path: Optional[str] = None
config_path: Optional[str] = None
candidate: Optional[NeoGoCandidate] = None
contract: Optional[NeoGoContract] = None
db: Optional[NeoGoDb] = None
nep17: Optional[NeoGoNep17] = None
node: Optional[NeoGoNode] = None
query: Optional[NeoGoQuery] = None
version: Optional[NeoGoVersion] = None
wallet: Optional[NeoGoWallet] = None
def __init__(
self,
shell: Shell,
neo_go_exec_path: Optional[str] = None,
config_path: Optional[str] = None,
):
self.candidate = NeoGoCandidate(
shell, neo_go_exec_path, config_path=config_path
)
self.contract = NeoGoContract(
self.neo_go_exec_path, config_path=config_path
)
self.db = NeoGoDb(shell, neo_go_exec_path, config_path=config_path)
self.nep17 = NeoGoNep17(shell, neo_go_exec_path, config_path=config_path)
self.node = NeoGoNode(shell, neo_go_exec_path, config_path=config_path)
self.query = NeoGoQuery(shell, neo_go_exec_path, config_path=config_path)
self.version = NeoGoVersion(shell, neo_go_exec_path, config_path=config_path)
self.wallet = NeoGoWallet(shell, neo_go_exec_path, config_path=config_path)

243
cli/go/nep17.py Normal file
View file

@ -0,0 +1,243 @@
from typing import List, Optional
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
class NeoGoNep17(NeofsCliCommand):
def balance(
self,
address: str,
token: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""Get address balance
Args:
address (str): Address to use
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
token (str): Token to use (hash or name (for NEO/GAS or imported tokens))
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet nep17 balance",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def import_token(
self,
address: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
token: Optional[str] = None,
rpc_endpoint: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""import NEP-17 token to a wallet
Args:
address (str): Token contract address or hash in LE
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
token (str): Token to use (hash or name (for NEO/GAS or imported tokens))
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet nep17 import",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def info(
self,
token: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
) -> CommandResult:
"""print imported NEP-17 token info
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
token (str): Token to use (hash or name (for NEO/GAS or imported tokens))
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet nep17 info",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def remove(
self,
token: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
force: bool = False,
) -> CommandResult:
"""remove NEP-17 token from the wallet
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
token (str): Token to use (hash or name (for NEO/GAS or imported tokens))
force (bool): Do not ask for a confirmation
Returns:
str: Command string
"""
return self._execute(
"wallet nep17 remove",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def transfer(
self,
token: str,
to_address: str,
sysgas: float,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
out: Optional[str] = None,
from_address: Optional[str] = None,
force: bool = False,
gas: Optional[float] = None,
amount: float = 0,
timeout: int = 10,
) -> CommandResult:
"""Transfers specified NEP-17 token amount with optional 'data' parameter and cosigners
list attached to the transfer. See 'contract testinvokefunction' documentation
for the details about 'data' parameter and cosigners syntax. If no 'data' is
given then default nil value will be used. If no cosigners are given then the
sender with CalledByEntry scope will be used as the only signer.
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
out (str): file to put JSON transaction to
from_address (str): Address to send an asset from
to_address (str): Address to send an asset to
token (str): Token to use (hash or name (for NEO/GAS or imported tokens))
force (bool): Do not ask for a confirmation
gas (float): network fee to add to the transaction (prioritizing it)
sysgas (float): system fee to add to transaction (compensating for execution)
force (bool): Do not ask for a confirmation
amount (float) Amount of asset to send
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet nep17 transfer",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def multitransfer(
self,
token: str,
to_address: List[str],
sysgas: float,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
out: Optional[str] = None,
from_address: Optional[str] = None,
force: bool = False,
gas: Optional[float] = None,
amount: float = 0,
timeout: int = 10,
) -> CommandResult:
"""transfer NEP-17 tokens to multiple recipients
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
out (str): file to put JSON transaction to
from_address (str): Address to send an asset from
to_address (str): Address to send an asset to
token (str): Token to use (hash or name (for NEO/GAS or imported tokens))
force (bool): Do not ask for a confirmation
gas (float): network fee to add to the transaction (prioritizing it)
sysgas (float): system fee to add to transaction (compensating for execution)
force (bool): Do not ask for a confirmation
amount (float) Amount of asset to send
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet nep17 multitransfer",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)

18
cli/go/node.py Normal file
View file

@ -0,0 +1,18 @@
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
from .blockchain_network_type import NetworkType
class NeoGoNode(NeofsCliCommand):
def start(self, network: NetworkType = NetworkType.PRIVATE) -> CommandResult:
"""Start a NEO node
Args:
network (NetworkType): Select network type (default: private)
Returns:
str: Command string
"""
return self._execute("start", **{network.value: True})

128
cli/go/query.py Normal file
View file

@ -0,0 +1,128 @@
from typing import Optional
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
class NeoGoQuery(NeofsCliCommand):
def candidates(
self,
rpc_endpoint: str,
timeout: int = 10,
) -> CommandResult:
"""Get candidates and votes
Args:
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
return self._execute(
"query candidates",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def committee(
self,
rpc_endpoint: str,
timeout: int = 10,
) -> CommandResult:
"""Get committee list
Args:
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
return self._execute(
"query committee",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def height(
self,
rpc_endpoint: str,
timeout: int = 10,
) -> CommandResult:
"""Get node height
Args:
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
return self._execute(
"query height",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)
def tx(
self,
tx_hash: str,
rpc_endpoint: str,
timeout: int = 10,
) -> CommandResult:
"""Query transaction status
Args:
tx_hash (str): Hash of transaction
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
return self._execute(
f"query tx {tx_hash}",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self", "hash"]
},
)
def voter(
self,
rpc_endpoint: str,
timeout: int = 10,
) -> CommandResult:
"""Print NEO holder account state
Args:
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
return self._execute(
"query voter",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
},
)

13
cli/go/version.py Normal file
View file

@ -0,0 +1,13 @@
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
class NeoGoVersion(NeofsCliCommand):
def get(self) -> CommandResult:
"""Application version
Returns:
str: Command string
"""
return self._execute("", version=True)

395
cli/go/wallet.py Normal file
View file

@ -0,0 +1,395 @@
from typing import Optional
from cli.cli_command import NeofsCliCommand
from shell import CommandResult
class NeoGoWallet(NeofsCliCommand):
def claim(
self,
address: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""claim GAS
Args:
address (str): Address to claim GAS for
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet claim",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def init(
self,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
account: bool = False,
) -> CommandResult:
"""create a new wallet
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
account (bool): Create a new account
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet init",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def convert(
self,
out: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
) -> CommandResult:
"""convert addresses from existing NEO2 NEP6-wallet to NEO3 format
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
out (str): where to write converted wallet
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet convert",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def create(
self,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
) -> CommandResult:
"""add an account to the existing wallet
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet create",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def dump(
self,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
decrypt: bool = False,
) -> CommandResult:
"""check and dump an existing NEO wallet
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
decrypt (bool): Decrypt encrypted keys.
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet dump",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def dump_keys(
self,
address: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
) -> CommandResult:
"""check and dump an existing NEO wallet
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
address (str): address to print public keys for
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet dump-keys",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def export(
self,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
decrypt: bool = False,
) -> CommandResult:
"""export keys for address
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
decrypt (bool): Decrypt encrypted keys.
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet export",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def import_wif(
self,
wif: str,
name: str,
contract: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
) -> CommandResult:
"""import WIF of a standard signature contract
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
wif (str): WIF to import
name (str): Optional account name
contract (str): Verification script for custom contracts
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet import",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def import_multisig(
self,
wif: str,
name: Optional[str] = None,
min_number: int = 0,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
) -> CommandResult:
"""import multisig contract
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
wif (str): WIF to import
name (str): Optional account name
min_number (int): Minimal number of signatures (default: 0)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet import-multisig",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def import_deployed(
self,
wif: str,
rpc_endpoint: str,
name: Optional[str] = None,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
contract: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""import multisig contract
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
wif (str): WIF to import
name (str): Optional account name
contract (str): Contract hash or address
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet import-deployed",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def remove(
self,
address: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
force: bool = False,
) -> CommandResult:
"""check and dump an existing NEO wallet
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
address (str): Account address or hash in LE form to be removed
force (bool): Do not ask for a confirmation
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet remove",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)
def sign(
self,
input_file: str,
address: str,
rpc_endpoint: str,
wallet: Optional[str] = None,
wallet_config: Optional[str] = None,
out: Optional[str] = None,
timeout: int = 10,
) -> CommandResult:
"""import multisig contract
Args:
wallet (str): Target location of the wallet file ('-' to read from stdin);
conflicts with --wallet-config flag.
wallet_config (str): Target location of the wallet config file;
conflicts with --wallet flag.
out (str): file to put JSON transaction to
input_file (str): file with JSON transaction
address (str): Address to use
rpc_endpoint (str): RPC node address
timeout (int): Timeout for the operation (default: 10s)
Returns:
str: Command string
"""
assert bool(wallet) ^ bool(wallet_config), self.WALLET_SOURCE_ERROR_MSG
return self._execute(
"wallet sign",
**{
param: param_value
for param, param_value in locals().items()
if param not in ["self"]
}
)