partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
valid
TransactionBuilder.set_fee_asset
Set asset to fee
graphenecommon/transactionbuilder.py
def set_fee_asset(self, fee_asset): """ Set asset to fee """ if isinstance(fee_asset, self.amount_class): self.fee_asset_id = fee_asset["id"] elif isinstance(fee_asset, self.asset_class): self.fee_asset_id = fee_asset["id"] elif fee_asset: self.fee_asset_id = fee_asset else: self.fee_asset_id = "1.3.0"
def set_fee_asset(self, fee_asset): """ Set asset to fee """ if isinstance(fee_asset, self.amount_class): self.fee_asset_id = fee_asset["id"] elif isinstance(fee_asset, self.asset_class): self.fee_asset_id = fee_asset["id"] elif fee_asset: self.fee_asset_id = fee_asset else: self.fee_asset_id = "1.3.0"
[ "Set", "asset", "to", "fee" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L329-L339
[ "def", "set_fee_asset", "(", "self", ",", "fee_asset", ")", ":", "if", "isinstance", "(", "fee_asset", ",", "self", ".", "amount_class", ")", ":", "self", ".", "fee_asset_id", "=", "fee_asset", "[", "\"id\"", "]", "elif", "isinstance", "(", "fee_asset", ",", "self", ".", "asset_class", ")", ":", "self", ".", "fee_asset_id", "=", "fee_asset", "[", "\"id\"", "]", "elif", "fee_asset", ":", "self", ".", "fee_asset_id", "=", "fee_asset", "else", ":", "self", ".", "fee_asset_id", "=", "\"1.3.0\"" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.add_required_fees
Auxiliary method to obtain the required fees for a set of operations. Requires a websocket connection to a witness node!
graphenecommon/transactionbuilder.py
def add_required_fees(self, ops, asset_id="1.3.0"): """ Auxiliary method to obtain the required fees for a set of operations. Requires a websocket connection to a witness node! """ ws = self.blockchain.rpc fees = ws.get_required_fees([i.json() for i in ops], asset_id) for i, d in enumerate(ops): if isinstance(fees[i], list): # Operation is a proposal ops[i].op.data["fee"] = Asset( amount=fees[i][0]["amount"], asset_id=fees[i][0]["asset_id"] ) for j, _ in enumerate(ops[i].op.data["proposed_ops"].data): ops[i].op.data["proposed_ops"].data[j].data["op"].op.data[ "fee" ] = Asset( amount=fees[i][1][j]["amount"], asset_id=fees[i][1][j]["asset_id"], ) else: # Operation is a regular operation ops[i].op.data["fee"] = Asset( amount=fees[i]["amount"], asset_id=fees[i]["asset_id"] ) return ops
def add_required_fees(self, ops, asset_id="1.3.0"): """ Auxiliary method to obtain the required fees for a set of operations. Requires a websocket connection to a witness node! """ ws = self.blockchain.rpc fees = ws.get_required_fees([i.json() for i in ops], asset_id) for i, d in enumerate(ops): if isinstance(fees[i], list): # Operation is a proposal ops[i].op.data["fee"] = Asset( amount=fees[i][0]["amount"], asset_id=fees[i][0]["asset_id"] ) for j, _ in enumerate(ops[i].op.data["proposed_ops"].data): ops[i].op.data["proposed_ops"].data[j].data["op"].op.data[ "fee" ] = Asset( amount=fees[i][1][j]["amount"], asset_id=fees[i][1][j]["asset_id"], ) else: # Operation is a regular operation ops[i].op.data["fee"] = Asset( amount=fees[i]["amount"], asset_id=fees[i]["asset_id"] ) return ops
[ "Auxiliary", "method", "to", "obtain", "the", "required", "fees", "for", "a", "set", "of", "operations", ".", "Requires", "a", "websocket", "connection", "to", "a", "witness", "node!" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L341-L365
[ "def", "add_required_fees", "(", "self", ",", "ops", ",", "asset_id", "=", "\"1.3.0\"", ")", ":", "ws", "=", "self", ".", "blockchain", ".", "rpc", "fees", "=", "ws", ".", "get_required_fees", "(", "[", "i", ".", "json", "(", ")", "for", "i", "in", "ops", "]", ",", "asset_id", ")", "for", "i", ",", "d", "in", "enumerate", "(", "ops", ")", ":", "if", "isinstance", "(", "fees", "[", "i", "]", ",", "list", ")", ":", "# Operation is a proposal", "ops", "[", "i", "]", ".", "op", ".", "data", "[", "\"fee\"", "]", "=", "Asset", "(", "amount", "=", "fees", "[", "i", "]", "[", "0", "]", "[", "\"amount\"", "]", ",", "asset_id", "=", "fees", "[", "i", "]", "[", "0", "]", "[", "\"asset_id\"", "]", ")", "for", "j", ",", "_", "in", "enumerate", "(", "ops", "[", "i", "]", ".", "op", ".", "data", "[", "\"proposed_ops\"", "]", ".", "data", ")", ":", "ops", "[", "i", "]", ".", "op", ".", "data", "[", "\"proposed_ops\"", "]", ".", "data", "[", "j", "]", ".", "data", "[", "\"op\"", "]", ".", "op", ".", "data", "[", "\"fee\"", "]", "=", "Asset", "(", "amount", "=", "fees", "[", "i", "]", "[", "1", "]", "[", "j", "]", "[", "\"amount\"", "]", ",", "asset_id", "=", "fees", "[", "i", "]", "[", "1", "]", "[", "j", "]", "[", "\"asset_id\"", "]", ",", ")", "else", ":", "# Operation is a regular operation", "ops", "[", "i", "]", ".", "op", ".", "data", "[", "\"fee\"", "]", "=", "Asset", "(", "amount", "=", "fees", "[", "i", "]", "[", "\"amount\"", "]", ",", "asset_id", "=", "fees", "[", "i", "]", "[", "\"asset_id\"", "]", ")", "return", "ops" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.constructTx
Construct the actual transaction and store it in the class's dict store
graphenecommon/transactionbuilder.py
def constructTx(self): """ Construct the actual transaction and store it in the class's dict store """ ops = list() for op in self.ops: if isinstance(op, ProposalBuilder): # This operation is a proposal an needs to be deal with # differently proposal = op.get_raw() if proposal: ops.append(proposal) elif isinstance(op, self.operation_class): ops.extend([op]) else: # otherwise, we simply wrap ops into Operations ops.extend([self.operation_class(op)]) # We now wrap everything into an actual transaction ops = self.add_required_fees(ops, asset_id=self.fee_asset_id) expiration = formatTimeFromNow( self.expiration or self.blockchain.expiration or 30 # defaults to 30 seconds ) ref_block_num, ref_block_prefix = self.get_block_params() self.tx = self.signed_transaction_class( ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops, ) dict.update(self, self.tx.json()) self._unset_require_reconstruction()
def constructTx(self): """ Construct the actual transaction and store it in the class's dict store """ ops = list() for op in self.ops: if isinstance(op, ProposalBuilder): # This operation is a proposal an needs to be deal with # differently proposal = op.get_raw() if proposal: ops.append(proposal) elif isinstance(op, self.operation_class): ops.extend([op]) else: # otherwise, we simply wrap ops into Operations ops.extend([self.operation_class(op)]) # We now wrap everything into an actual transaction ops = self.add_required_fees(ops, asset_id=self.fee_asset_id) expiration = formatTimeFromNow( self.expiration or self.blockchain.expiration or 30 # defaults to 30 seconds ) ref_block_num, ref_block_prefix = self.get_block_params() self.tx = self.signed_transaction_class( ref_block_num=ref_block_num, ref_block_prefix=ref_block_prefix, expiration=expiration, operations=ops, ) dict.update(self, self.tx.json()) self._unset_require_reconstruction()
[ "Construct", "the", "actual", "transaction", "and", "store", "it", "in", "the", "class", "s", "dict", "store" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L367-L400
[ "def", "constructTx", "(", "self", ")", ":", "ops", "=", "list", "(", ")", "for", "op", "in", "self", ".", "ops", ":", "if", "isinstance", "(", "op", ",", "ProposalBuilder", ")", ":", "# This operation is a proposal an needs to be deal with", "# differently", "proposal", "=", "op", ".", "get_raw", "(", ")", "if", "proposal", ":", "ops", ".", "append", "(", "proposal", ")", "elif", "isinstance", "(", "op", ",", "self", ".", "operation_class", ")", ":", "ops", ".", "extend", "(", "[", "op", "]", ")", "else", ":", "# otherwise, we simply wrap ops into Operations", "ops", ".", "extend", "(", "[", "self", ".", "operation_class", "(", "op", ")", "]", ")", "# We now wrap everything into an actual transaction", "ops", "=", "self", ".", "add_required_fees", "(", "ops", ",", "asset_id", "=", "self", ".", "fee_asset_id", ")", "expiration", "=", "formatTimeFromNow", "(", "self", ".", "expiration", "or", "self", ".", "blockchain", ".", "expiration", "or", "30", "# defaults to 30 seconds", ")", "ref_block_num", ",", "ref_block_prefix", "=", "self", ".", "get_block_params", "(", ")", "self", ".", "tx", "=", "self", ".", "signed_transaction_class", "(", "ref_block_num", "=", "ref_block_num", ",", "ref_block_prefix", "=", "ref_block_prefix", ",", "expiration", "=", "expiration", ",", "operations", "=", "ops", ",", ")", "dict", ".", "update", "(", "self", ",", "self", ".", "tx", ".", "json", "(", ")", ")", "self", ".", "_unset_require_reconstruction", "(", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.get_block_params
Auxiliary method to obtain ``ref_block_num`` and ``ref_block_prefix``. Requires a websocket connection to a witness node!
graphenecommon/transactionbuilder.py
def get_block_params(self): """ Auxiliary method to obtain ``ref_block_num`` and ``ref_block_prefix``. Requires a websocket connection to a witness node! """ ws = self.blockchain.rpc dynBCParams = ws.get_dynamic_global_properties() ref_block_num = dynBCParams["head_block_number"] & 0xFFFF ref_block_prefix = struct.unpack_from( "<I", unhexlify(dynBCParams["head_block_id"]), 4 )[0] return ref_block_num, ref_block_prefix
def get_block_params(self): """ Auxiliary method to obtain ``ref_block_num`` and ``ref_block_prefix``. Requires a websocket connection to a witness node! """ ws = self.blockchain.rpc dynBCParams = ws.get_dynamic_global_properties() ref_block_num = dynBCParams["head_block_number"] & 0xFFFF ref_block_prefix = struct.unpack_from( "<I", unhexlify(dynBCParams["head_block_id"]), 4 )[0] return ref_block_num, ref_block_prefix
[ "Auxiliary", "method", "to", "obtain", "ref_block_num", "and", "ref_block_prefix", ".", "Requires", "a", "websocket", "connection", "to", "a", "witness", "node!" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L402-L413
[ "def", "get_block_params", "(", "self", ")", ":", "ws", "=", "self", ".", "blockchain", ".", "rpc", "dynBCParams", "=", "ws", ".", "get_dynamic_global_properties", "(", ")", "ref_block_num", "=", "dynBCParams", "[", "\"head_block_number\"", "]", "&", "0xFFFF", "ref_block_prefix", "=", "struct", ".", "unpack_from", "(", "\"<I\"", ",", "unhexlify", "(", "dynBCParams", "[", "\"head_block_id\"", "]", ")", ",", "4", ")", "[", "0", "]", "return", "ref_block_num", ",", "ref_block_prefix" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.sign
Sign a provided transaction with the provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions.
graphenecommon/transactionbuilder.py
def sign(self): """ Sign a provided transaction with the provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions. """ self.constructTx() if "operations" not in self or not self["operations"]: return # Legacy compatibility! # If we are doing a proposal, obtain the account from the proposer_id if self.blockchain.proposer: proposer = self.account_class( self.blockchain.proposer, blockchain_instance=self.blockchain ) self.wifs = set() self.signing_accounts = list() self.appendSigner(proposer["id"], "active") # We need to set the default prefix, otherwise pubkeys are # presented wrongly! if self.blockchain.rpc: self.operations.default_prefix = self.blockchain.rpc.chain_params["prefix"] elif "blockchain" in self: self.operations.default_prefix = self["blockchain"]["prefix"] try: signedtx = self.signed_transaction_class(**self.json()) except Exception: raise ValueError("Invalid TransactionBuilder Format") if not any(self.wifs): raise MissingKeyError signedtx.sign(self.wifs, chain=self.blockchain.rpc.chain_params) self["signatures"].extend(signedtx.json().get("signatures")) return signedtx
def sign(self): """ Sign a provided transaction with the provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions. """ self.constructTx() if "operations" not in self or not self["operations"]: return # Legacy compatibility! # If we are doing a proposal, obtain the account from the proposer_id if self.blockchain.proposer: proposer = self.account_class( self.blockchain.proposer, blockchain_instance=self.blockchain ) self.wifs = set() self.signing_accounts = list() self.appendSigner(proposer["id"], "active") # We need to set the default prefix, otherwise pubkeys are # presented wrongly! if self.blockchain.rpc: self.operations.default_prefix = self.blockchain.rpc.chain_params["prefix"] elif "blockchain" in self: self.operations.default_prefix = self["blockchain"]["prefix"] try: signedtx = self.signed_transaction_class(**self.json()) except Exception: raise ValueError("Invalid TransactionBuilder Format") if not any(self.wifs): raise MissingKeyError signedtx.sign(self.wifs, chain=self.blockchain.rpc.chain_params) self["signatures"].extend(signedtx.json().get("signatures")) return signedtx
[ "Sign", "a", "provided", "transaction", "with", "the", "provided", "key", "(", "s", ")" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L415-L456
[ "def", "sign", "(", "self", ")", ":", "self", ".", "constructTx", "(", ")", "if", "\"operations\"", "not", "in", "self", "or", "not", "self", "[", "\"operations\"", "]", ":", "return", "# Legacy compatibility!", "# If we are doing a proposal, obtain the account from the proposer_id", "if", "self", ".", "blockchain", ".", "proposer", ":", "proposer", "=", "self", ".", "account_class", "(", "self", ".", "blockchain", ".", "proposer", ",", "blockchain_instance", "=", "self", ".", "blockchain", ")", "self", ".", "wifs", "=", "set", "(", ")", "self", ".", "signing_accounts", "=", "list", "(", ")", "self", ".", "appendSigner", "(", "proposer", "[", "\"id\"", "]", ",", "\"active\"", ")", "# We need to set the default prefix, otherwise pubkeys are", "# presented wrongly!", "if", "self", ".", "blockchain", ".", "rpc", ":", "self", ".", "operations", ".", "default_prefix", "=", "self", ".", "blockchain", ".", "rpc", ".", "chain_params", "[", "\"prefix\"", "]", "elif", "\"blockchain\"", "in", "self", ":", "self", ".", "operations", ".", "default_prefix", "=", "self", "[", "\"blockchain\"", "]", "[", "\"prefix\"", "]", "try", ":", "signedtx", "=", "self", ".", "signed_transaction_class", "(", "*", "*", "self", ".", "json", "(", ")", ")", "except", "Exception", ":", "raise", "ValueError", "(", "\"Invalid TransactionBuilder Format\"", ")", "if", "not", "any", "(", "self", ".", "wifs", ")", ":", "raise", "MissingKeyError", "signedtx", ".", "sign", "(", "self", ".", "wifs", ",", "chain", "=", "self", ".", "blockchain", ".", "rpc", ".", "chain_params", ")", "self", "[", "\"signatures\"", "]", ".", "extend", "(", "signedtx", ".", "json", "(", ")", ".", "get", "(", "\"signatures\"", ")", ")", "return", "signedtx" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.verify_authority
Verify the authority of the signed transaction
graphenecommon/transactionbuilder.py
def verify_authority(self): """ Verify the authority of the signed transaction """ try: if not self.blockchain.rpc.verify_authority(self.json()): raise InsufficientAuthorityError except Exception as e: raise e
def verify_authority(self): """ Verify the authority of the signed transaction """ try: if not self.blockchain.rpc.verify_authority(self.json()): raise InsufficientAuthorityError except Exception as e: raise e
[ "Verify", "the", "authority", "of", "the", "signed", "transaction" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L458-L465
[ "def", "verify_authority", "(", "self", ")", ":", "try", ":", "if", "not", "self", ".", "blockchain", ".", "rpc", ".", "verify_authority", "(", "self", ".", "json", "(", ")", ")", ":", "raise", "InsufficientAuthorityError", "except", "Exception", "as", "e", ":", "raise", "e" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.broadcast
Broadcast a transaction to the blockchain network :param tx tx: Signed transaction to broadcast
graphenecommon/transactionbuilder.py
def broadcast(self): """ Broadcast a transaction to the blockchain network :param tx tx: Signed transaction to broadcast """ # Sign if not signed if not self._is_signed(): self.sign() # Cannot broadcast an empty transaction if "operations" not in self or not self["operations"]: log.warning("No operations in transaction! Returning") return # Obtain JS ret = self.json() # Debugging mode does not broadcast if self.blockchain.nobroadcast: log.warning("Not broadcasting anything!") self.clear() return ret # Broadcast try: if self.blockchain.blocking: ret = self.blockchain.rpc.broadcast_transaction_synchronous( ret, api="network_broadcast" ) ret.update(**ret.get("trx", {})) else: self.blockchain.rpc.broadcast_transaction(ret, api="network_broadcast") except Exception as e: raise e finally: self.clear() return ret
def broadcast(self): """ Broadcast a transaction to the blockchain network :param tx tx: Signed transaction to broadcast """ # Sign if not signed if not self._is_signed(): self.sign() # Cannot broadcast an empty transaction if "operations" not in self or not self["operations"]: log.warning("No operations in transaction! Returning") return # Obtain JS ret = self.json() # Debugging mode does not broadcast if self.blockchain.nobroadcast: log.warning("Not broadcasting anything!") self.clear() return ret # Broadcast try: if self.blockchain.blocking: ret = self.blockchain.rpc.broadcast_transaction_synchronous( ret, api="network_broadcast" ) ret.update(**ret.get("trx", {})) else: self.blockchain.rpc.broadcast_transaction(ret, api="network_broadcast") except Exception as e: raise e finally: self.clear() return ret
[ "Broadcast", "a", "transaction", "to", "the", "blockchain", "network" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L467-L504
[ "def", "broadcast", "(", "self", ")", ":", "# Sign if not signed", "if", "not", "self", ".", "_is_signed", "(", ")", ":", "self", ".", "sign", "(", ")", "# Cannot broadcast an empty transaction", "if", "\"operations\"", "not", "in", "self", "or", "not", "self", "[", "\"operations\"", "]", ":", "log", ".", "warning", "(", "\"No operations in transaction! Returning\"", ")", "return", "# Obtain JS", "ret", "=", "self", ".", "json", "(", ")", "# Debugging mode does not broadcast", "if", "self", ".", "blockchain", ".", "nobroadcast", ":", "log", ".", "warning", "(", "\"Not broadcasting anything!\"", ")", "self", ".", "clear", "(", ")", "return", "ret", "# Broadcast", "try", ":", "if", "self", ".", "blockchain", ".", "blocking", ":", "ret", "=", "self", ".", "blockchain", ".", "rpc", ".", "broadcast_transaction_synchronous", "(", "ret", ",", "api", "=", "\"network_broadcast\"", ")", "ret", ".", "update", "(", "*", "*", "ret", ".", "get", "(", "\"trx\"", ",", "{", "}", ")", ")", "else", ":", "self", ".", "blockchain", ".", "rpc", ".", "broadcast_transaction", "(", "ret", ",", "api", "=", "\"network_broadcast\"", ")", "except", "Exception", "as", "e", ":", "raise", "e", "finally", ":", "self", ".", "clear", "(", ")", "return", "ret" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.clear
Clear the transaction builder and start from scratch
graphenecommon/transactionbuilder.py
def clear(self): """ Clear the transaction builder and start from scratch """ self.ops = [] self.wifs = set() self.signing_accounts = [] # This makes sure that _is_constructed will return False afterwards self["expiration"] = None dict.__init__(self, {})
def clear(self): """ Clear the transaction builder and start from scratch """ self.ops = [] self.wifs = set() self.signing_accounts = [] # This makes sure that _is_constructed will return False afterwards self["expiration"] = None dict.__init__(self, {})
[ "Clear", "the", "transaction", "builder", "and", "start", "from", "scratch" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L506-L514
[ "def", "clear", "(", "self", ")", ":", "self", ".", "ops", "=", "[", "]", "self", ".", "wifs", "=", "set", "(", ")", "self", ".", "signing_accounts", "=", "[", "]", "# This makes sure that _is_constructed will return False afterwards", "self", "[", "\"expiration\"", "]", "=", "None", "dict", ".", "__init__", "(", "self", ",", "{", "}", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.addSigningInformation
This is a private method that adds side information to a unsigned/partial transaction in order to simplify later signing (e.g. for multisig or coldstorage) FIXME: Does not work with owner keys!
graphenecommon/transactionbuilder.py
def addSigningInformation(self, account, permission): """ This is a private method that adds side information to a unsigned/partial transaction in order to simplify later signing (e.g. for multisig or coldstorage) FIXME: Does not work with owner keys! """ self.constructTx() self["blockchain"] = self.blockchain.rpc.chain_params if isinstance(account, self.publickey_class): self["missing_signatures"] = [str(account)] else: accountObj = self.account_class(account) authority = accountObj[permission] # We add a required_authorities to be able to identify # how to sign later. This is an array, because we # may later want to allow multiple operations per tx self.update({"required_authorities": {accountObj["name"]: authority}}) for account_auth in authority["account_auths"]: account_auth_account = self.account_class(account_auth[0]) self["required_authorities"].update( {account_auth[0]: account_auth_account.get(permission)} ) # Try to resolve required signatures for offline signing self["missing_signatures"] = [x[0] for x in authority["key_auths"]] # Add one recursion of keys from account_auths: for account_auth in authority["account_auths"]: account_auth_account = self.account_class(account_auth[0]) self["missing_signatures"].extend( [x[0] for x in account_auth_account[permission]["key_auths"]] )
def addSigningInformation(self, account, permission): """ This is a private method that adds side information to a unsigned/partial transaction in order to simplify later signing (e.g. for multisig or coldstorage) FIXME: Does not work with owner keys! """ self.constructTx() self["blockchain"] = self.blockchain.rpc.chain_params if isinstance(account, self.publickey_class): self["missing_signatures"] = [str(account)] else: accountObj = self.account_class(account) authority = accountObj[permission] # We add a required_authorities to be able to identify # how to sign later. This is an array, because we # may later want to allow multiple operations per tx self.update({"required_authorities": {accountObj["name"]: authority}}) for account_auth in authority["account_auths"]: account_auth_account = self.account_class(account_auth[0]) self["required_authorities"].update( {account_auth[0]: account_auth_account.get(permission)} ) # Try to resolve required signatures for offline signing self["missing_signatures"] = [x[0] for x in authority["key_auths"]] # Add one recursion of keys from account_auths: for account_auth in authority["account_auths"]: account_auth_account = self.account_class(account_auth[0]) self["missing_signatures"].extend( [x[0] for x in account_auth_account[permission]["key_auths"]] )
[ "This", "is", "a", "private", "method", "that", "adds", "side", "information", "to", "a", "unsigned", "/", "partial", "transaction", "in", "order", "to", "simplify", "later", "signing", "(", "e", ".", "g", ".", "for", "multisig", "or", "coldstorage", ")" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L516-L548
[ "def", "addSigningInformation", "(", "self", ",", "account", ",", "permission", ")", ":", "self", ".", "constructTx", "(", ")", "self", "[", "\"blockchain\"", "]", "=", "self", ".", "blockchain", ".", "rpc", ".", "chain_params", "if", "isinstance", "(", "account", ",", "self", ".", "publickey_class", ")", ":", "self", "[", "\"missing_signatures\"", "]", "=", "[", "str", "(", "account", ")", "]", "else", ":", "accountObj", "=", "self", ".", "account_class", "(", "account", ")", "authority", "=", "accountObj", "[", "permission", "]", "# We add a required_authorities to be able to identify", "# how to sign later. This is an array, because we", "# may later want to allow multiple operations per tx", "self", ".", "update", "(", "{", "\"required_authorities\"", ":", "{", "accountObj", "[", "\"name\"", "]", ":", "authority", "}", "}", ")", "for", "account_auth", "in", "authority", "[", "\"account_auths\"", "]", ":", "account_auth_account", "=", "self", ".", "account_class", "(", "account_auth", "[", "0", "]", ")", "self", "[", "\"required_authorities\"", "]", ".", "update", "(", "{", "account_auth", "[", "0", "]", ":", "account_auth_account", ".", "get", "(", "permission", ")", "}", ")", "# Try to resolve required signatures for offline signing", "self", "[", "\"missing_signatures\"", "]", "=", "[", "x", "[", "0", "]", "for", "x", "in", "authority", "[", "\"key_auths\"", "]", "]", "# Add one recursion of keys from account_auths:", "for", "account_auth", "in", "authority", "[", "\"account_auths\"", "]", ":", "account_auth_account", "=", "self", ".", "account_class", "(", "account_auth", "[", "0", "]", ")", "self", "[", "\"missing_signatures\"", "]", ".", "extend", "(", "[", "x", "[", "0", "]", "for", "x", "in", "account_auth_account", "[", "permission", "]", "[", "\"key_auths\"", "]", "]", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
TransactionBuilder.appendMissingSignatures
Store which accounts/keys are supposed to sign the transaction This method is used for an offline-signer!
graphenecommon/transactionbuilder.py
def appendMissingSignatures(self): """ Store which accounts/keys are supposed to sign the transaction This method is used for an offline-signer! """ missing_signatures = self.get("missing_signatures", []) for pub in missing_signatures: wif = self.blockchain.wallet.getPrivateKeyForPublicKey(pub) if wif: self.appendWif(wif)
def appendMissingSignatures(self): """ Store which accounts/keys are supposed to sign the transaction This method is used for an offline-signer! """ missing_signatures = self.get("missing_signatures", []) for pub in missing_signatures: wif = self.blockchain.wallet.getPrivateKeyForPublicKey(pub) if wif: self.appendWif(wif)
[ "Store", "which", "accounts", "/", "keys", "are", "supposed", "to", "sign", "the", "transaction" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/transactionbuilder.py#L550-L559
[ "def", "appendMissingSignatures", "(", "self", ")", ":", "missing_signatures", "=", "self", ".", "get", "(", "\"missing_signatures\"", ",", "[", "]", ")", "for", "pub", "in", "missing_signatures", ":", "wif", "=", "self", ".", "blockchain", ".", "wallet", ".", "getPrivateKeyForPublicKey", "(", "pub", ")", "if", "wif", ":", "self", ".", "appendWif", "(", "wif", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Price.as_base
Returns the price instance so that the base asset is ``base``. Note: This makes a copy of the object!
graphenecommon/price.py
def as_base(self, base): """ Returns the price instance so that the base asset is ``base``. Note: This makes a copy of the object! """ if base == self["base"]["symbol"]: return self.copy() elif base == self["quote"]["symbol"]: return self.copy().invert() else: raise InvalidAssetException
def as_base(self, base): """ Returns the price instance so that the base asset is ``base``. Note: This makes a copy of the object! """ if base == self["base"]["symbol"]: return self.copy() elif base == self["quote"]["symbol"]: return self.copy().invert() else: raise InvalidAssetException
[ "Returns", "the", "price", "instance", "so", "that", "the", "base", "asset", "is", "base", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/price.py#L255-L265
[ "def", "as_base", "(", "self", ",", "base", ")", ":", "if", "base", "==", "self", "[", "\"base\"", "]", "[", "\"symbol\"", "]", ":", "return", "self", ".", "copy", "(", ")", "elif", "base", "==", "self", "[", "\"quote\"", "]", "[", "\"symbol\"", "]", ":", "return", "self", ".", "copy", "(", ")", ".", "invert", "(", ")", "else", ":", "raise", "InvalidAssetException" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Price.as_quote
Returns the price instance so that the quote asset is ``quote``. Note: This makes a copy of the object!
graphenecommon/price.py
def as_quote(self, quote): """ Returns the price instance so that the quote asset is ``quote``. Note: This makes a copy of the object! """ if quote == self["quote"]["symbol"]: return self.copy() elif quote == self["base"]["symbol"]: return self.copy().invert() else: raise InvalidAssetException
def as_quote(self, quote): """ Returns the price instance so that the quote asset is ``quote``. Note: This makes a copy of the object! """ if quote == self["quote"]["symbol"]: return self.copy() elif quote == self["base"]["symbol"]: return self.copy().invert() else: raise InvalidAssetException
[ "Returns", "the", "price", "instance", "so", "that", "the", "quote", "asset", "is", "quote", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/price.py#L267-L277
[ "def", "as_quote", "(", "self", ",", "quote", ")", ":", "if", "quote", "==", "self", "[", "\"quote\"", "]", "[", "\"symbol\"", "]", ":", "return", "self", ".", "copy", "(", ")", "elif", "quote", "==", "self", "[", "\"base\"", "]", "[", "\"symbol\"", "]", ":", "return", "self", ".", "copy", "(", ")", ".", "invert", "(", ")", "else", ":", "raise", "InvalidAssetException" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Price.invert
Invert the price (e.g. go from ``USD/BTS`` into ``BTS/USD``)
graphenecommon/price.py
def invert(self): """ Invert the price (e.g. go from ``USD/BTS`` into ``BTS/USD``) """ tmp = self["quote"] self["quote"] = self["base"] self["base"] = tmp if "for_sale" in self and self["for_sale"]: self["for_sale"] = self.amount_class( self["for_sale"]["amount"] * self["price"], self["base"]["symbol"] ) return self
def invert(self): """ Invert the price (e.g. go from ``USD/BTS`` into ``BTS/USD``) """ tmp = self["quote"] self["quote"] = self["base"] self["base"] = tmp if "for_sale" in self and self["for_sale"]: self["for_sale"] = self.amount_class( self["for_sale"]["amount"] * self["price"], self["base"]["symbol"] ) return self
[ "Invert", "the", "price", "(", "e", ".", "g", ".", "go", "from", "USD", "/", "BTS", "into", "BTS", "/", "USD", ")" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/price.py#L279-L289
[ "def", "invert", "(", "self", ")", ":", "tmp", "=", "self", "[", "\"quote\"", "]", "self", "[", "\"quote\"", "]", "=", "self", "[", "\"base\"", "]", "self", "[", "\"base\"", "]", "=", "tmp", "if", "\"for_sale\"", "in", "self", "and", "self", "[", "\"for_sale\"", "]", ":", "self", "[", "\"for_sale\"", "]", "=", "self", ".", "amount_class", "(", "self", "[", "\"for_sale\"", "]", "[", "\"amount\"", "]", "*", "self", "[", "\"price\"", "]", ",", "self", "[", "\"base\"", "]", "[", "\"symbol\"", "]", ")", "return", "self" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Price.json
return { "base": self["base"].json(), "quote": self["quote"].json() }
graphenecommon/price.py
def json(self): """ return { "base": self["base"].json(), "quote": self["quote"].json() } """ quote = self["quote"] base = self["base"] frac = Fraction(int(quote) / int(base)).limit_denominator( 10 ** base["asset"]["precision"] ) return { "base": {"amount": int(frac.denominator), "asset_id": base["asset"]["id"]}, "quote": {"amount": int(frac.numerator), "asset_id": quote["asset"]["id"]}, }
def json(self): """ return { "base": self["base"].json(), "quote": self["quote"].json() } """ quote = self["quote"] base = self["base"] frac = Fraction(int(quote) / int(base)).limit_denominator( 10 ** base["asset"]["precision"] ) return { "base": {"amount": int(frac.denominator), "asset_id": base["asset"]["id"]}, "quote": {"amount": int(frac.numerator), "asset_id": quote["asset"]["id"]}, }
[ "return", "{", "base", ":", "self", "[", "base", "]", ".", "json", "()", "quote", ":", "self", "[", "quote", "]", ".", "json", "()", "}" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/price.py#L291-L306
[ "def", "json", "(", "self", ")", ":", "quote", "=", "self", "[", "\"quote\"", "]", "base", "=", "self", "[", "\"base\"", "]", "frac", "=", "Fraction", "(", "int", "(", "quote", ")", "/", "int", "(", "base", ")", ")", ".", "limit_denominator", "(", "10", "**", "base", "[", "\"asset\"", "]", "[", "\"precision\"", "]", ")", "return", "{", "\"base\"", ":", "{", "\"amount\"", ":", "int", "(", "frac", ".", "denominator", ")", ",", "\"asset_id\"", ":", "base", "[", "\"asset\"", "]", "[", "\"id\"", "]", "}", ",", "\"quote\"", ":", "{", "\"amount\"", ":", "int", "(", "frac", ".", "numerator", ")", ",", "\"asset_id\"", ":", "quote", "[", "\"asset\"", "]", "[", "\"id\"", "]", "}", ",", "}" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
InRamStore.wipe
Wipe the store
graphenestorage/ram.py
def wipe(self): """ Wipe the store """ keys = list(self.keys()).copy() for key in keys: self.delete(key)
def wipe(self): """ Wipe the store """ keys = list(self.keys()).copy() for key in keys: self.delete(key)
[ "Wipe", "the", "store" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenestorage/ram.py#L26-L31
[ "def", "wipe", "(", "self", ")", ":", "keys", "=", "list", "(", "self", ".", "keys", "(", ")", ")", ".", "copy", "(", ")", "for", "key", "in", "keys", ":", "self", ".", "delete", "(", "key", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AbstractGrapheneChain.connect
Connect to blockchain network (internal use only)
graphenecommon/chain.py
def connect(self, node="", rpcuser="", rpcpassword="", **kwargs): """ Connect to blockchain network (internal use only) """ if not node: if "node" in self.config: node = self.config["node"] else: raise ValueError("A Blockchain node needs to be provided!") if not rpcuser and "rpcuser" in self.config: rpcuser = self.config["rpcuser"] if not rpcpassword and "rpcpassword" in self.config: rpcpassword = self.config["rpcpassword"] self.rpc = self.rpc_class(node, rpcuser, rpcpassword, **kwargs)
def connect(self, node="", rpcuser="", rpcpassword="", **kwargs): """ Connect to blockchain network (internal use only) """ if not node: if "node" in self.config: node = self.config["node"] else: raise ValueError("A Blockchain node needs to be provided!") if not rpcuser and "rpcuser" in self.config: rpcuser = self.config["rpcuser"] if not rpcpassword and "rpcpassword" in self.config: rpcpassword = self.config["rpcpassword"] self.rpc = self.rpc_class(node, rpcuser, rpcpassword, **kwargs)
[ "Connect", "to", "blockchain", "network", "(", "internal", "use", "only", ")" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/chain.py#L60-L75
[ "def", "connect", "(", "self", ",", "node", "=", "\"\"", ",", "rpcuser", "=", "\"\"", ",", "rpcpassword", "=", "\"\"", ",", "*", "*", "kwargs", ")", ":", "if", "not", "node", ":", "if", "\"node\"", "in", "self", ".", "config", ":", "node", "=", "self", ".", "config", "[", "\"node\"", "]", "else", ":", "raise", "ValueError", "(", "\"A Blockchain node needs to be provided!\"", ")", "if", "not", "rpcuser", "and", "\"rpcuser\"", "in", "self", ".", "config", ":", "rpcuser", "=", "self", ".", "config", "[", "\"rpcuser\"", "]", "if", "not", "rpcpassword", "and", "\"rpcpassword\"", "in", "self", ".", "config", ":", "rpcpassword", "=", "self", ".", "config", "[", "\"rpcpassword\"", "]", "self", ".", "rpc", "=", "self", ".", "rpc_class", "(", "node", ",", "rpcuser", ",", "rpcpassword", ",", "*", "*", "kwargs", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AbstractGrapheneChain.finalizeOp
This method obtains the required private keys if present in the wallet, finalizes the transaction, signs it and broadacasts it :param operation ops: The operation (or list of operaions) to broadcast :param operation account: The account that authorizes the operation :param string permission: The required permission for signing (active, owner, posting) :param object append_to: This allows to provide an instance of ProposalsBuilder (see :func:`new_proposal`) or TransactionBuilder (see :func:`new_tx()`) to specify where to put a specific operation. ... note:: ``append_to`` is exposed to every method used in the this class ... note:: If ``ops`` is a list of operation, they all need to be signable by the same key! Thus, you cannot combine ops that require active permission with ops that require posting permission. Neither can you use different accounts for different operations! ... note:: This uses ``txbuffer`` as instance of :class:`transactionbuilder.TransactionBuilder`. You may want to use your own txbuffer
graphenecommon/chain.py
def finalizeOp(self, ops, account, permission, **kwargs): """ This method obtains the required private keys if present in the wallet, finalizes the transaction, signs it and broadacasts it :param operation ops: The operation (or list of operaions) to broadcast :param operation account: The account that authorizes the operation :param string permission: The required permission for signing (active, owner, posting) :param object append_to: This allows to provide an instance of ProposalsBuilder (see :func:`new_proposal`) or TransactionBuilder (see :func:`new_tx()`) to specify where to put a specific operation. ... note:: ``append_to`` is exposed to every method used in the this class ... note:: If ``ops`` is a list of operation, they all need to be signable by the same key! Thus, you cannot combine ops that require active permission with ops that require posting permission. Neither can you use different accounts for different operations! ... note:: This uses ``txbuffer`` as instance of :class:`transactionbuilder.TransactionBuilder`. You may want to use your own txbuffer """ if "append_to" in kwargs and kwargs["append_to"]: if self.proposer: log.warning( "You may not use append_to and self.proposer at " "the same time. Append new_proposal(..) instead" ) # Append to the append_to and return append_to = kwargs["append_to"] parent = append_to.get_parent() assert isinstance( append_to, (self.transactionbuilder_class, self.proposalbuilder_class) ) append_to.appendOps(ops) # Add the signer to the buffer so we sign the tx properly if isinstance(append_to, self.proposalbuilder_class): parent.appendSigner(append_to.proposer, permission) else: parent.appendSigner(account, permission) # This returns as we used append_to, it does NOT broadcast, or sign return append_to.get_parent() elif self.proposer: # Legacy proposer mode! proposal = self.proposal() proposal.set_proposer(self.proposer) proposal.set_expiration(self.proposal_expiration) proposal.set_review(self.proposal_review) proposal.appendOps(ops) # Go forward to see what the other options do ... else: # Append tot he default buffer self.txbuffer.appendOps(ops) # The API that obtains the fee only allows to specify one particular # fee asset for all operations in that transaction even though the # blockchain itself could allow to pay multiple operations with # different fee assets. if "fee_asset" in kwargs and kwargs["fee_asset"]: self.txbuffer.set_fee_asset(kwargs["fee_asset"]) # Add signing information, signer, sign and optionally broadcast if self.unsigned: # In case we don't want to sign anything self.txbuffer.addSigningInformation(account, permission) return self.txbuffer elif self.bundle: # In case we want to add more ops to the tx (bundle) self.txbuffer.appendSigner(account, permission) return self.txbuffer.json() else: # default behavior: sign + broadcast self.txbuffer.appendSigner(account, permission) self.txbuffer.sign() return self.txbuffer.broadcast()
def finalizeOp(self, ops, account, permission, **kwargs): """ This method obtains the required private keys if present in the wallet, finalizes the transaction, signs it and broadacasts it :param operation ops: The operation (or list of operaions) to broadcast :param operation account: The account that authorizes the operation :param string permission: The required permission for signing (active, owner, posting) :param object append_to: This allows to provide an instance of ProposalsBuilder (see :func:`new_proposal`) or TransactionBuilder (see :func:`new_tx()`) to specify where to put a specific operation. ... note:: ``append_to`` is exposed to every method used in the this class ... note:: If ``ops`` is a list of operation, they all need to be signable by the same key! Thus, you cannot combine ops that require active permission with ops that require posting permission. Neither can you use different accounts for different operations! ... note:: This uses ``txbuffer`` as instance of :class:`transactionbuilder.TransactionBuilder`. You may want to use your own txbuffer """ if "append_to" in kwargs and kwargs["append_to"]: if self.proposer: log.warning( "You may not use append_to and self.proposer at " "the same time. Append new_proposal(..) instead" ) # Append to the append_to and return append_to = kwargs["append_to"] parent = append_to.get_parent() assert isinstance( append_to, (self.transactionbuilder_class, self.proposalbuilder_class) ) append_to.appendOps(ops) # Add the signer to the buffer so we sign the tx properly if isinstance(append_to, self.proposalbuilder_class): parent.appendSigner(append_to.proposer, permission) else: parent.appendSigner(account, permission) # This returns as we used append_to, it does NOT broadcast, or sign return append_to.get_parent() elif self.proposer: # Legacy proposer mode! proposal = self.proposal() proposal.set_proposer(self.proposer) proposal.set_expiration(self.proposal_expiration) proposal.set_review(self.proposal_review) proposal.appendOps(ops) # Go forward to see what the other options do ... else: # Append tot he default buffer self.txbuffer.appendOps(ops) # The API that obtains the fee only allows to specify one particular # fee asset for all operations in that transaction even though the # blockchain itself could allow to pay multiple operations with # different fee assets. if "fee_asset" in kwargs and kwargs["fee_asset"]: self.txbuffer.set_fee_asset(kwargs["fee_asset"]) # Add signing information, signer, sign and optionally broadcast if self.unsigned: # In case we don't want to sign anything self.txbuffer.addSigningInformation(account, permission) return self.txbuffer elif self.bundle: # In case we want to add more ops to the tx (bundle) self.txbuffer.appendSigner(account, permission) return self.txbuffer.json() else: # default behavior: sign + broadcast self.txbuffer.appendSigner(account, permission) self.txbuffer.sign() return self.txbuffer.broadcast()
[ "This", "method", "obtains", "the", "required", "private", "keys", "if", "present", "in", "the", "wallet", "finalizes", "the", "transaction", "signs", "it", "and", "broadacasts", "it" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/chain.py#L144-L227
[ "def", "finalizeOp", "(", "self", ",", "ops", ",", "account", ",", "permission", ",", "*", "*", "kwargs", ")", ":", "if", "\"append_to\"", "in", "kwargs", "and", "kwargs", "[", "\"append_to\"", "]", ":", "if", "self", ".", "proposer", ":", "log", ".", "warning", "(", "\"You may not use append_to and self.proposer at \"", "\"the same time. Append new_proposal(..) instead\"", ")", "# Append to the append_to and return", "append_to", "=", "kwargs", "[", "\"append_to\"", "]", "parent", "=", "append_to", ".", "get_parent", "(", ")", "assert", "isinstance", "(", "append_to", ",", "(", "self", ".", "transactionbuilder_class", ",", "self", ".", "proposalbuilder_class", ")", ")", "append_to", ".", "appendOps", "(", "ops", ")", "# Add the signer to the buffer so we sign the tx properly", "if", "isinstance", "(", "append_to", ",", "self", ".", "proposalbuilder_class", ")", ":", "parent", ".", "appendSigner", "(", "append_to", ".", "proposer", ",", "permission", ")", "else", ":", "parent", ".", "appendSigner", "(", "account", ",", "permission", ")", "# This returns as we used append_to, it does NOT broadcast, or sign", "return", "append_to", ".", "get_parent", "(", ")", "elif", "self", ".", "proposer", ":", "# Legacy proposer mode!", "proposal", "=", "self", ".", "proposal", "(", ")", "proposal", ".", "set_proposer", "(", "self", ".", "proposer", ")", "proposal", ".", "set_expiration", "(", "self", ".", "proposal_expiration", ")", "proposal", ".", "set_review", "(", "self", ".", "proposal_review", ")", "proposal", ".", "appendOps", "(", "ops", ")", "# Go forward to see what the other options do ...", "else", ":", "# Append tot he default buffer", "self", ".", "txbuffer", ".", "appendOps", "(", "ops", ")", "# The API that obtains the fee only allows to specify one particular", "# fee asset for all operations in that transaction even though the", "# blockchain itself could allow to pay multiple operations with", "# different fee assets.", "if", "\"fee_asset\"", "in", "kwargs", "and", "kwargs", "[", "\"fee_asset\"", "]", ":", "self", ".", "txbuffer", ".", "set_fee_asset", "(", "kwargs", "[", "\"fee_asset\"", "]", ")", "# Add signing information, signer, sign and optionally broadcast", "if", "self", ".", "unsigned", ":", "# In case we don't want to sign anything", "self", ".", "txbuffer", ".", "addSigningInformation", "(", "account", ",", "permission", ")", "return", "self", ".", "txbuffer", "elif", "self", ".", "bundle", ":", "# In case we want to add more ops to the tx (bundle)", "self", ".", "txbuffer", ".", "appendSigner", "(", "account", ",", "permission", ")", "return", "self", ".", "txbuffer", ".", "json", "(", ")", "else", ":", "# default behavior: sign + broadcast", "self", ".", "txbuffer", ".", "appendSigner", "(", "account", ",", "permission", ")", "self", ".", "txbuffer", ".", "sign", "(", ")", "return", "self", ".", "txbuffer", ".", "broadcast", "(", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AbstractGrapheneChain.sign
Sign a provided transaction witht he provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions.
graphenecommon/chain.py
def sign(self, tx=None, wifs=[]): """ Sign a provided transaction witht he provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions. """ if tx: txbuffer = self.transactionbuilder_class(tx, blockchain_instance=self) else: txbuffer = self.txbuffer txbuffer.appendWif(wifs) txbuffer.appendMissingSignatures() txbuffer.sign() return txbuffer.json()
def sign(self, tx=None, wifs=[]): """ Sign a provided transaction witht he provided key(s) :param dict tx: The transaction to be signed and returned :param string wifs: One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in "missing_signatures" key of the transactions. """ if tx: txbuffer = self.transactionbuilder_class(tx, blockchain_instance=self) else: txbuffer = self.txbuffer txbuffer.appendWif(wifs) txbuffer.appendMissingSignatures() txbuffer.sign() return txbuffer.json()
[ "Sign", "a", "provided", "transaction", "witht", "he", "provided", "key", "(", "s", ")" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/chain.py#L229-L245
[ "def", "sign", "(", "self", ",", "tx", "=", "None", ",", "wifs", "=", "[", "]", ")", ":", "if", "tx", ":", "txbuffer", "=", "self", ".", "transactionbuilder_class", "(", "tx", ",", "blockchain_instance", "=", "self", ")", "else", ":", "txbuffer", "=", "self", ".", "txbuffer", "txbuffer", ".", "appendWif", "(", "wifs", ")", "txbuffer", ".", "appendMissingSignatures", "(", ")", "txbuffer", ".", "sign", "(", ")", "return", "txbuffer", ".", "json", "(", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AbstractGrapheneChain.broadcast
Broadcast a transaction to the Blockchain :param tx tx: Signed transaction to broadcast
graphenecommon/chain.py
def broadcast(self, tx=None): """ Broadcast a transaction to the Blockchain :param tx tx: Signed transaction to broadcast """ if tx: # If tx is provided, we broadcast the tx return self.transactionbuilder_class( tx, blockchain_instance=self ).broadcast() else: return self.txbuffer.broadcast()
def broadcast(self, tx=None): """ Broadcast a transaction to the Blockchain :param tx tx: Signed transaction to broadcast """ if tx: # If tx is provided, we broadcast the tx return self.transactionbuilder_class( tx, blockchain_instance=self ).broadcast() else: return self.txbuffer.broadcast()
[ "Broadcast", "a", "transaction", "to", "the", "Blockchain" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/chain.py#L247-L258
[ "def", "broadcast", "(", "self", ",", "tx", "=", "None", ")", ":", "if", "tx", ":", "# If tx is provided, we broadcast the tx", "return", "self", ".", "transactionbuilder_class", "(", "tx", ",", "blockchain_instance", "=", "self", ")", ".", "broadcast", "(", ")", "else", ":", "return", "self", ".", "txbuffer", ".", "broadcast", "(", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AbstractGrapheneChain.proposal
Return the default proposal buffer ... note:: If any parameter is set, the default proposal parameters will be changed!
graphenecommon/chain.py
def proposal(self, proposer=None, proposal_expiration=None, proposal_review=None): """ Return the default proposal buffer ... note:: If any parameter is set, the default proposal parameters will be changed! """ if not self._propbuffer: return self.new_proposal( self.tx(), proposer, proposal_expiration, proposal_review ) if proposer: self._propbuffer[0].set_proposer(proposer) if proposal_expiration: self._propbuffer[0].set_expiration(proposal_expiration) if proposal_review: self._propbuffer[0].set_review(proposal_review) return self._propbuffer[0]
def proposal(self, proposer=None, proposal_expiration=None, proposal_review=None): """ Return the default proposal buffer ... note:: If any parameter is set, the default proposal parameters will be changed! """ if not self._propbuffer: return self.new_proposal( self.tx(), proposer, proposal_expiration, proposal_review ) if proposer: self._propbuffer[0].set_proposer(proposer) if proposal_expiration: self._propbuffer[0].set_expiration(proposal_expiration) if proposal_review: self._propbuffer[0].set_review(proposal_review) return self._propbuffer[0]
[ "Return", "the", "default", "proposal", "buffer" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/chain.py#L280-L296
[ "def", "proposal", "(", "self", ",", "proposer", "=", "None", ",", "proposal_expiration", "=", "None", ",", "proposal_review", "=", "None", ")", ":", "if", "not", "self", ".", "_propbuffer", ":", "return", "self", ".", "new_proposal", "(", "self", ".", "tx", "(", ")", ",", "proposer", ",", "proposal_expiration", ",", "proposal_review", ")", "if", "proposer", ":", "self", ".", "_propbuffer", "[", "0", "]", ".", "set_proposer", "(", "proposer", ")", "if", "proposal_expiration", ":", "self", ".", "_propbuffer", "[", "0", "]", ".", "set_expiration", "(", "proposal_expiration", ")", "if", "proposal_review", ":", "self", ".", "_propbuffer", "[", "0", "]", ".", "set_review", "(", "proposal_review", ")", "return", "self", ".", "_propbuffer", "[", "0", "]" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AbstractGrapheneChain.new_tx
Let's obtain a new txbuffer :returns int txid: id of the new txbuffer
graphenecommon/chain.py
def new_tx(self, *args, **kwargs): """ Let's obtain a new txbuffer :returns int txid: id of the new txbuffer """ builder = self.transactionbuilder_class( *args, blockchain_instance=self, **kwargs ) self._txbuffers.append(builder) return builder
def new_tx(self, *args, **kwargs): """ Let's obtain a new txbuffer :returns int txid: id of the new txbuffer """ builder = self.transactionbuilder_class( *args, blockchain_instance=self, **kwargs ) self._txbuffers.append(builder) return builder
[ "Let", "s", "obtain", "a", "new", "txbuffer" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/chain.py#L332-L341
[ "def", "new_tx", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "builder", "=", "self", ".", "transactionbuilder_class", "(", "*", "args", ",", "blockchain_instance", "=", "self", ",", "*", "*", "kwargs", ")", "self", ".", "_txbuffers", ".", "append", "(", "builder", ")", "return", "builder" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
AccountOptions.detail
This is an example how to sort votes prior to using them in the Object
graphenebase/operations.py
def detail(self, *args, **kwargs): prefix = kwargs.pop("prefix", default_prefix) # remove dublicates kwargs["votes"] = list(set(kwargs["votes"])) """ This is an example how to sort votes prior to using them in the Object """ # # Sort votes # kwargs["votes"] = sorted( # kwargs["votes"], # key=lambda x: float(x.split(":")[1]), # ) return OrderedDict( [ ("memo_key", PublicKey(kwargs["memo_key"], prefix=prefix)), ("voting_account", ObjectId(kwargs["voting_account"], "account")), ("num_witness", Uint16(kwargs["num_witness"])), ("num_committee", Uint16(kwargs["num_committee"])), ("votes", Array([VoteId(o) for o in kwargs["votes"]])), ("extensions", Set([])), ] )
def detail(self, *args, **kwargs): prefix = kwargs.pop("prefix", default_prefix) # remove dublicates kwargs["votes"] = list(set(kwargs["votes"])) """ This is an example how to sort votes prior to using them in the Object """ # # Sort votes # kwargs["votes"] = sorted( # kwargs["votes"], # key=lambda x: float(x.split(":")[1]), # ) return OrderedDict( [ ("memo_key", PublicKey(kwargs["memo_key"], prefix=prefix)), ("voting_account", ObjectId(kwargs["voting_account"], "account")), ("num_witness", Uint16(kwargs["num_witness"])), ("num_committee", Uint16(kwargs["num_committee"])), ("votes", Array([VoteId(o) for o in kwargs["votes"]])), ("extensions", Set([])), ] )
[ "This", "is", "an", "example", "how", "to", "sort", "votes", "prior", "to", "using", "them", "in", "the", "Object" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/operations.py#L88-L109
[ "def", "detail", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "prefix", "=", "kwargs", ".", "pop", "(", "\"prefix\"", ",", "default_prefix", ")", "# remove dublicates", "kwargs", "[", "\"votes\"", "]", "=", "list", "(", "set", "(", "kwargs", "[", "\"votes\"", "]", ")", ")", "# # Sort votes", "# kwargs[\"votes\"] = sorted(", "# kwargs[\"votes\"],", "# key=lambda x: float(x.split(\":\")[1]),", "# )", "return", "OrderedDict", "(", "[", "(", "\"memo_key\"", ",", "PublicKey", "(", "kwargs", "[", "\"memo_key\"", "]", ",", "prefix", "=", "prefix", ")", ")", ",", "(", "\"voting_account\"", ",", "ObjectId", "(", "kwargs", "[", "\"voting_account\"", "]", ",", "\"account\"", ")", ")", ",", "(", "\"num_witness\"", ",", "Uint16", "(", "kwargs", "[", "\"num_witness\"", "]", ")", ")", ",", "(", "\"num_committee\"", ",", "Uint16", "(", "kwargs", "[", "\"num_committee\"", "]", ")", ")", ",", "(", "\"votes\"", ",", "Array", "(", "[", "VoteId", "(", "o", ")", "for", "o", "in", "kwargs", "[", "\"votes\"", "]", "]", ")", ")", ",", "(", "\"extensions\"", ",", "Set", "(", "[", "]", ")", ")", ",", "]", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Signed_Transaction.id
The transaction id of this transaction
graphenebase/signedtransactions.py
def id(self): """ The transaction id of this transaction """ # Store signatures temporarily since they are not part of # transaction id sigs = self.data["signatures"] self.data.pop("signatures", None) # Generage Hash of the seriliazed version h = hashlib.sha256(bytes(self)).digest() # recover signatures self.data["signatures"] = sigs # Return properly truncated tx hash return hexlify(h[:20]).decode("ascii")
def id(self): """ The transaction id of this transaction """ # Store signatures temporarily since they are not part of # transaction id sigs = self.data["signatures"] self.data.pop("signatures", None) # Generage Hash of the seriliazed version h = hashlib.sha256(bytes(self)).digest() # recover signatures self.data["signatures"] = sigs # Return properly truncated tx hash return hexlify(h[:20]).decode("ascii")
[ "The", "transaction", "id", "of", "this", "transaction" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/signedtransactions.py#L84-L99
[ "def", "id", "(", "self", ")", ":", "# Store signatures temporarily since they are not part of", "# transaction id", "sigs", "=", "self", ".", "data", "[", "\"signatures\"", "]", "self", ".", "data", ".", "pop", "(", "\"signatures\"", ",", "None", ")", "# Generage Hash of the seriliazed version", "h", "=", "hashlib", ".", "sha256", "(", "bytes", "(", "self", ")", ")", ".", "digest", "(", ")", "# recover signatures", "self", ".", "data", "[", "\"signatures\"", "]", "=", "sigs", "# Return properly truncated tx hash", "return", "hexlify", "(", "h", "[", ":", "20", "]", ")", ".", "decode", "(", "\"ascii\"", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Signed_Transaction.sign
Sign the transaction with the provided private keys. :param array wifkeys: Array of wif keys :param str chain: identifier for the chain
graphenebase/signedtransactions.py
def sign(self, wifkeys, chain=None): """ Sign the transaction with the provided private keys. :param array wifkeys: Array of wif keys :param str chain: identifier for the chain """ if not chain: chain = self.get_default_prefix() self.deriveDigest(chain) # Get Unique private keys self.privkeys = [] for item in wifkeys: if item not in self.privkeys: self.privkeys.append(item) # Sign the message with every private key given! sigs = [] for wif in self.privkeys: signature = sign_message(self.message, wif) sigs.append(Signature(signature)) self.data["signatures"] = Array(sigs) return self
def sign(self, wifkeys, chain=None): """ Sign the transaction with the provided private keys. :param array wifkeys: Array of wif keys :param str chain: identifier for the chain """ if not chain: chain = self.get_default_prefix() self.deriveDigest(chain) # Get Unique private keys self.privkeys = [] for item in wifkeys: if item not in self.privkeys: self.privkeys.append(item) # Sign the message with every private key given! sigs = [] for wif in self.privkeys: signature = sign_message(self.message, wif) sigs.append(Signature(signature)) self.data["signatures"] = Array(sigs) return self
[ "Sign", "the", "transaction", "with", "the", "provided", "private", "keys", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/signedtransactions.py#L179-L203
[ "def", "sign", "(", "self", ",", "wifkeys", ",", "chain", "=", "None", ")", ":", "if", "not", "chain", ":", "chain", "=", "self", ".", "get_default_prefix", "(", ")", "self", ".", "deriveDigest", "(", "chain", ")", "# Get Unique private keys", "self", ".", "privkeys", "=", "[", "]", "for", "item", "in", "wifkeys", ":", "if", "item", "not", "in", "self", ".", "privkeys", ":", "self", ".", "privkeys", ".", "append", "(", "item", ")", "# Sign the message with every private key given!", "sigs", "=", "[", "]", "for", "wif", "in", "self", ".", "privkeys", ":", "signature", "=", "sign_message", "(", "self", ".", "message", ",", "wif", ")", "sigs", ".", "append", "(", "Signature", "(", "signature", ")", ")", "self", ".", "data", "[", "\"signatures\"", "]", "=", "Array", "(", "sigs", ")", "return", "self" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
BlockchainObjects.store
Cache the list :param list data: List of objects to cache
graphenecommon/blockchainobject.py
def store(self, data, key=None, *args, **kwargs): """ Cache the list :param list data: List of objects to cache """ list.__init__(self, data) self._store_items(self._cache_key(key))
def store(self, data, key=None, *args, **kwargs): """ Cache the list :param list data: List of objects to cache """ list.__init__(self, data) self._store_items(self._cache_key(key))
[ "Cache", "the", "list" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/blockchainobject.py#L176-L182
[ "def", "store", "(", "self", ",", "data", ",", "key", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "list", ".", "__init__", "(", "self", ",", "data", ")", "self", ".", "_store_items", "(", "self", ".", "_cache_key", "(", "key", ")", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
BlockchainObject.store
Cache the list :param list data: List of objects to cache
graphenecommon/blockchainobject.py
def store(self, data, key="id"): """ Cache the list :param list data: List of objects to cache """ dict.__init__(self, data) self._store_item(key)
def store(self, data, key="id"): """ Cache the list :param list data: List of objects to cache """ dict.__init__(self, data) self._store_item(key)
[ "Cache", "the", "list" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/blockchainobject.py#L267-L273
[ "def", "store", "(", "self", ",", "data", ",", "key", "=", "\"id\"", ")", ":", "dict", ".", "__init__", "(", "self", ",", "data", ")", "self", ".", "_store_item", "(", "key", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
BlockchainObject.objectid_valid
Test if a string looks like a regular object id of the form::: xxxx.yyyyy.zzzz with those being numbers.
graphenecommon/blockchainobject.py
def objectid_valid(i): """ Test if a string looks like a regular object id of the form::: xxxx.yyyyy.zzzz with those being numbers. """ if "." not in i: return False parts = i.split(".") if len(parts) == 3: try: [int(x) for x in parts] return True except Exception: pass return False
def objectid_valid(i): """ Test if a string looks like a regular object id of the form::: xxxx.yyyyy.zzzz with those being numbers. """ if "." not in i: return False parts = i.split(".") if len(parts) == 3: try: [int(x) for x in parts] return True except Exception: pass return False
[ "Test", "if", "a", "string", "looks", "like", "a", "regular", "object", "id", "of", "the", "form", ":::" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/blockchainobject.py#L289-L306
[ "def", "objectid_valid", "(", "i", ")", ":", "if", "\".\"", "not", "in", "i", ":", "return", "False", "parts", "=", "i", ".", "split", "(", "\".\"", ")", "if", "len", "(", "parts", ")", "==", "3", ":", "try", ":", "[", "int", "(", "x", ")", "for", "x", "in", "parts", "]", "return", "True", "except", "Exception", ":", "pass", "return", "False" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Object.refresh
This is the refresh method that overloads the prototype in BlockchainObject.
graphenecommon/blockchainobject.py
def refresh(self): """ This is the refresh method that overloads the prototype in BlockchainObject. """ dict.__init__( self, self.blockchain.rpc.get_object(self.identifier), blockchain_instance=self.blockchain, )
def refresh(self): """ This is the refresh method that overloads the prototype in BlockchainObject. """ dict.__init__( self, self.blockchain.rpc.get_object(self.identifier), blockchain_instance=self.blockchain, )
[ "This", "is", "the", "refresh", "method", "that", "overloads", "the", "prototype", "in", "BlockchainObject", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/blockchainobject.py#L337-L345
[ "def", "refresh", "(", "self", ")", ":", "dict", ".", "__init__", "(", "self", ",", "self", ".", "blockchain", ".", "rpc", ".", "get_object", "(", "self", ".", "identifier", ")", ",", "blockchain_instance", "=", "self", ".", "blockchain", ",", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
_encrypt_xor
Returns encrypt(a ^ b).
graphenebase/bip38.py
def _encrypt_xor(a, b, aes): """ Returns encrypt(a ^ b). """ a = unhexlify("%0.32x" % (int((a), 16) ^ int(hexlify(b), 16))) return aes.encrypt(a)
def _encrypt_xor(a, b, aes): """ Returns encrypt(a ^ b). """ a = unhexlify("%0.32x" % (int((a), 16) ^ int(hexlify(b), 16))) return aes.encrypt(a)
[ "Returns", "encrypt", "(", "a", "^", "b", ")", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/bip38.py#L40-L43
[ "def", "_encrypt_xor", "(", "a", ",", "b", ",", "aes", ")", ":", "a", "=", "unhexlify", "(", "\"%0.32x\"", "%", "(", "int", "(", "(", "a", ")", ",", "16", ")", "^", "int", "(", "hexlify", "(", "b", ")", ",", "16", ")", ")", ")", "return", "aes", ".", "encrypt", "(", "a", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
encrypt
BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey. :param privkey: Private key :type privkey: Base58 :param str passphrase: UTF-8 encoded passphrase for encryption :return: BIP0038 non-ec-multiply encrypted wif key :rtype: Base58
graphenebase/bip38.py
def encrypt(privkey, passphrase): """ BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey. :param privkey: Private key :type privkey: Base58 :param str passphrase: UTF-8 encoded passphrase for encryption :return: BIP0038 non-ec-multiply encrypted wif key :rtype: Base58 """ if isinstance(privkey, str): privkey = PrivateKey(privkey) else: privkey = PrivateKey(repr(privkey)) privkeyhex = repr(privkey) # hex addr = format(privkey.bitcoin.address, "BTC") a = _bytes(addr) salt = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4] if SCRYPT_MODULE == "scrypt": # pragma: no cover key = scrypt.hash(passphrase, salt, 16384, 8, 8) elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8) else: # pragma: no cover raise ValueError("No scrypt module loaded") # pragma: no cover (derived_half1, derived_half2) = (key[:32], key[32:]) aes = AES.new(derived_half2, AES.MODE_ECB) encrypted_half1 = _encrypt_xor(privkeyhex[:32], derived_half1[:16], aes) encrypted_half2 = _encrypt_xor(privkeyhex[32:], derived_half1[16:], aes) " flag byte is forced 0xc0 because Graphene only uses compressed keys " payload = b"\x01" + b"\x42" + b"\xc0" + salt + encrypted_half1 + encrypted_half2 " Checksum " checksum = hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] privatkey = hexlify(payload + checksum).decode("ascii") return Base58(privatkey)
def encrypt(privkey, passphrase): """ BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey. :param privkey: Private key :type privkey: Base58 :param str passphrase: UTF-8 encoded passphrase for encryption :return: BIP0038 non-ec-multiply encrypted wif key :rtype: Base58 """ if isinstance(privkey, str): privkey = PrivateKey(privkey) else: privkey = PrivateKey(repr(privkey)) privkeyhex = repr(privkey) # hex addr = format(privkey.bitcoin.address, "BTC") a = _bytes(addr) salt = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4] if SCRYPT_MODULE == "scrypt": # pragma: no cover key = scrypt.hash(passphrase, salt, 16384, 8, 8) elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8) else: # pragma: no cover raise ValueError("No scrypt module loaded") # pragma: no cover (derived_half1, derived_half2) = (key[:32], key[32:]) aes = AES.new(derived_half2, AES.MODE_ECB) encrypted_half1 = _encrypt_xor(privkeyhex[:32], derived_half1[:16], aes) encrypted_half2 = _encrypt_xor(privkeyhex[32:], derived_half1[16:], aes) " flag byte is forced 0xc0 because Graphene only uses compressed keys " payload = b"\x01" + b"\x42" + b"\xc0" + salt + encrypted_half1 + encrypted_half2 " Checksum " checksum = hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4] privatkey = hexlify(payload + checksum).decode("ascii") return Base58(privatkey)
[ "BIP0038", "non", "-", "ec", "-", "multiply", "encryption", ".", "Returns", "BIP0038", "encrypted", "privkey", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/bip38.py#L46-L80
[ "def", "encrypt", "(", "privkey", ",", "passphrase", ")", ":", "if", "isinstance", "(", "privkey", ",", "str", ")", ":", "privkey", "=", "PrivateKey", "(", "privkey", ")", "else", ":", "privkey", "=", "PrivateKey", "(", "repr", "(", "privkey", ")", ")", "privkeyhex", "=", "repr", "(", "privkey", ")", "# hex", "addr", "=", "format", "(", "privkey", ".", "bitcoin", ".", "address", ",", "\"BTC\"", ")", "a", "=", "_bytes", "(", "addr", ")", "salt", "=", "hashlib", ".", "sha256", "(", "hashlib", ".", "sha256", "(", "a", ")", ".", "digest", "(", ")", ")", ".", "digest", "(", ")", "[", "0", ":", "4", "]", "if", "SCRYPT_MODULE", "==", "\"scrypt\"", ":", "# pragma: no cover", "key", "=", "scrypt", ".", "hash", "(", "passphrase", ",", "salt", ",", "16384", ",", "8", ",", "8", ")", "elif", "SCRYPT_MODULE", "==", "\"pylibscrypt\"", ":", "# pragma: no cover", "key", "=", "scrypt", ".", "scrypt", "(", "bytes", "(", "passphrase", ",", "\"utf-8\"", ")", ",", "salt", ",", "16384", ",", "8", ",", "8", ")", "else", ":", "# pragma: no cover", "raise", "ValueError", "(", "\"No scrypt module loaded\"", ")", "# pragma: no cover", "(", "derived_half1", ",", "derived_half2", ")", "=", "(", "key", "[", ":", "32", "]", ",", "key", "[", "32", ":", "]", ")", "aes", "=", "AES", ".", "new", "(", "derived_half2", ",", "AES", ".", "MODE_ECB", ")", "encrypted_half1", "=", "_encrypt_xor", "(", "privkeyhex", "[", ":", "32", "]", ",", "derived_half1", "[", ":", "16", "]", ",", "aes", ")", "encrypted_half2", "=", "_encrypt_xor", "(", "privkeyhex", "[", "32", ":", "]", ",", "derived_half1", "[", "16", ":", "]", ",", "aes", ")", "\" flag byte is forced 0xc0 because Graphene only uses compressed keys \"", "payload", "=", "b\"\\x01\"", "+", "b\"\\x42\"", "+", "b\"\\xc0\"", "+", "salt", "+", "encrypted_half1", "+", "encrypted_half2", "\" Checksum \"", "checksum", "=", "hashlib", ".", "sha256", "(", "hashlib", ".", "sha256", "(", "payload", ")", ".", "digest", "(", ")", ")", ".", "digest", "(", ")", "[", ":", "4", "]", "privatkey", "=", "hexlify", "(", "payload", "+", "checksum", ")", ".", "decode", "(", "\"ascii\"", ")", "return", "Base58", "(", "privatkey", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
decrypt
BIP0038 non-ec-multiply decryption. Returns WIF privkey. :param Base58 encrypted_privkey: Private key :param str passphrase: UTF-8 encoded passphrase for decryption :return: BIP0038 non-ec-multiply decrypted key :rtype: Base58 :raises SaltException: if checksum verification failed (e.g. wrong password)
graphenebase/bip38.py
def decrypt(encrypted_privkey, passphrase): """BIP0038 non-ec-multiply decryption. Returns WIF privkey. :param Base58 encrypted_privkey: Private key :param str passphrase: UTF-8 encoded passphrase for decryption :return: BIP0038 non-ec-multiply decrypted key :rtype: Base58 :raises SaltException: if checksum verification failed (e.g. wrong password) """ d = unhexlify(base58decode(encrypted_privkey)) d = d[2:] # remove trailing 0x01 and 0x42 flagbyte = d[0:1] # get flag byte d = d[1:] # get payload assert flagbyte == b"\xc0", "Flagbyte has to be 0xc0" salt = d[0:4] d = d[4:-4] if SCRYPT_MODULE == "scrypt": # pragma: no cover key = scrypt.hash(passphrase, salt, 16384, 8, 8) elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8) else: raise ValueError("No scrypt module loaded") # pragma: no cover derivedhalf1 = key[0:32] derivedhalf2 = key[32:64] encryptedhalf1 = d[0:16] encryptedhalf2 = d[16:32] aes = AES.new(derivedhalf2, AES.MODE_ECB) decryptedhalf2 = aes.decrypt(encryptedhalf2) decryptedhalf1 = aes.decrypt(encryptedhalf1) privraw = decryptedhalf1 + decryptedhalf2 privraw = "%064x" % (int(hexlify(privraw), 16) ^ int(hexlify(derivedhalf1), 16)) wif = Base58(privraw) """ Verify Salt """ privkey = PrivateKey(format(wif, "wif")) addr = format(privkey.bitcoin.address, "BTC") a = _bytes(addr) saltverify = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4] if saltverify != salt: # pragma: no cover raise SaltException("checksum verification failed! Password may be incorrect.") return wif
def decrypt(encrypted_privkey, passphrase): """BIP0038 non-ec-multiply decryption. Returns WIF privkey. :param Base58 encrypted_privkey: Private key :param str passphrase: UTF-8 encoded passphrase for decryption :return: BIP0038 non-ec-multiply decrypted key :rtype: Base58 :raises SaltException: if checksum verification failed (e.g. wrong password) """ d = unhexlify(base58decode(encrypted_privkey)) d = d[2:] # remove trailing 0x01 and 0x42 flagbyte = d[0:1] # get flag byte d = d[1:] # get payload assert flagbyte == b"\xc0", "Flagbyte has to be 0xc0" salt = d[0:4] d = d[4:-4] if SCRYPT_MODULE == "scrypt": # pragma: no cover key = scrypt.hash(passphrase, salt, 16384, 8, 8) elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8) else: raise ValueError("No scrypt module loaded") # pragma: no cover derivedhalf1 = key[0:32] derivedhalf2 = key[32:64] encryptedhalf1 = d[0:16] encryptedhalf2 = d[16:32] aes = AES.new(derivedhalf2, AES.MODE_ECB) decryptedhalf2 = aes.decrypt(encryptedhalf2) decryptedhalf1 = aes.decrypt(encryptedhalf1) privraw = decryptedhalf1 + decryptedhalf2 privraw = "%064x" % (int(hexlify(privraw), 16) ^ int(hexlify(derivedhalf1), 16)) wif = Base58(privraw) """ Verify Salt """ privkey = PrivateKey(format(wif, "wif")) addr = format(privkey.bitcoin.address, "BTC") a = _bytes(addr) saltverify = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4] if saltverify != salt: # pragma: no cover raise SaltException("checksum verification failed! Password may be incorrect.") return wif
[ "BIP0038", "non", "-", "ec", "-", "multiply", "decryption", ".", "Returns", "WIF", "privkey", "." ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/bip38.py#L83-L125
[ "def", "decrypt", "(", "encrypted_privkey", ",", "passphrase", ")", ":", "d", "=", "unhexlify", "(", "base58decode", "(", "encrypted_privkey", ")", ")", "d", "=", "d", "[", "2", ":", "]", "# remove trailing 0x01 and 0x42", "flagbyte", "=", "d", "[", "0", ":", "1", "]", "# get flag byte", "d", "=", "d", "[", "1", ":", "]", "# get payload", "assert", "flagbyte", "==", "b\"\\xc0\"", ",", "\"Flagbyte has to be 0xc0\"", "salt", "=", "d", "[", "0", ":", "4", "]", "d", "=", "d", "[", "4", ":", "-", "4", "]", "if", "SCRYPT_MODULE", "==", "\"scrypt\"", ":", "# pragma: no cover", "key", "=", "scrypt", ".", "hash", "(", "passphrase", ",", "salt", ",", "16384", ",", "8", ",", "8", ")", "elif", "SCRYPT_MODULE", "==", "\"pylibscrypt\"", ":", "# pragma: no cover", "key", "=", "scrypt", ".", "scrypt", "(", "bytes", "(", "passphrase", ",", "\"utf-8\"", ")", ",", "salt", ",", "16384", ",", "8", ",", "8", ")", "else", ":", "raise", "ValueError", "(", "\"No scrypt module loaded\"", ")", "# pragma: no cover", "derivedhalf1", "=", "key", "[", "0", ":", "32", "]", "derivedhalf2", "=", "key", "[", "32", ":", "64", "]", "encryptedhalf1", "=", "d", "[", "0", ":", "16", "]", "encryptedhalf2", "=", "d", "[", "16", ":", "32", "]", "aes", "=", "AES", ".", "new", "(", "derivedhalf2", ",", "AES", ".", "MODE_ECB", ")", "decryptedhalf2", "=", "aes", ".", "decrypt", "(", "encryptedhalf2", ")", "decryptedhalf1", "=", "aes", ".", "decrypt", "(", "encryptedhalf1", ")", "privraw", "=", "decryptedhalf1", "+", "decryptedhalf2", "privraw", "=", "\"%064x\"", "%", "(", "int", "(", "hexlify", "(", "privraw", ")", ",", "16", ")", "^", "int", "(", "hexlify", "(", "derivedhalf1", ")", ",", "16", ")", ")", "wif", "=", "Base58", "(", "privraw", ")", "\"\"\" Verify Salt \"\"\"", "privkey", "=", "PrivateKey", "(", "format", "(", "wif", ",", "\"wif\"", ")", ")", "addr", "=", "format", "(", "privkey", ".", "bitcoin", ".", "address", ",", "\"BTC\"", ")", "a", "=", "_bytes", "(", "addr", ")", "saltverify", "=", "hashlib", ".", "sha256", "(", "hashlib", ".", "sha256", "(", "a", ")", ".", "digest", "(", ")", ")", ".", "digest", "(", ")", "[", "0", ":", "4", "]", "if", "saltverify", "!=", "salt", ":", "# pragma: no cover", "raise", "SaltException", "(", "\"checksum verification failed! Password may be incorrect.\"", ")", "return", "wif" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.setKeys
This method is strictly only for in memory keys that are passed to Wallet with the ``keys`` argument
graphenecommon/wallet.py
def setKeys(self, loadkeys): """ This method is strictly only for in memory keys that are passed to Wallet with the ``keys`` argument """ log.debug("Force setting of private keys. Not using the wallet database!") if isinstance(loadkeys, dict): loadkeys = list(loadkeys.values()) elif not isinstance(loadkeys, (list, set)): loadkeys = [loadkeys] for wif in loadkeys: pub = self.publickey_from_wif(wif) self.store.add(str(wif), pub)
def setKeys(self, loadkeys): """ This method is strictly only for in memory keys that are passed to Wallet with the ``keys`` argument """ log.debug("Force setting of private keys. Not using the wallet database!") if isinstance(loadkeys, dict): loadkeys = list(loadkeys.values()) elif not isinstance(loadkeys, (list, set)): loadkeys = [loadkeys] for wif in loadkeys: pub = self.publickey_from_wif(wif) self.store.add(str(wif), pub)
[ "This", "method", "is", "strictly", "only", "for", "in", "memory", "keys", "that", "are", "passed", "to", "Wallet", "with", "the", "keys", "argument" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L82-L93
[ "def", "setKeys", "(", "self", ",", "loadkeys", ")", ":", "log", ".", "debug", "(", "\"Force setting of private keys. Not using the wallet database!\"", ")", "if", "isinstance", "(", "loadkeys", ",", "dict", ")", ":", "loadkeys", "=", "list", "(", "loadkeys", ".", "values", "(", ")", ")", "elif", "not", "isinstance", "(", "loadkeys", ",", "(", "list", ",", "set", ")", ")", ":", "loadkeys", "=", "[", "loadkeys", "]", "for", "wif", "in", "loadkeys", ":", "pub", "=", "self", ".", "publickey_from_wif", "(", "wif", ")", "self", ".", "store", ".", "add", "(", "str", "(", "wif", ")", ",", "pub", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.unlock
Unlock the wallet database
graphenecommon/wallet.py
def unlock(self, pwd): """ Unlock the wallet database """ if self.store.is_encrypted(): return self.store.unlock(pwd)
def unlock(self, pwd): """ Unlock the wallet database """ if self.store.is_encrypted(): return self.store.unlock(pwd)
[ "Unlock", "the", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L100-L104
[ "def", "unlock", "(", "self", ",", "pwd", ")", ":", "if", "self", ".", "store", ".", "is_encrypted", "(", ")", ":", "return", "self", ".", "store", ".", "unlock", "(", "pwd", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.newWallet
Create a new wallet database
graphenecommon/wallet.py
def newWallet(self, pwd): """ Create a new wallet database """ if self.created(): raise WalletExists("You already have created a wallet!") self.store.unlock(pwd)
def newWallet(self, pwd): """ Create a new wallet database """ if self.created(): raise WalletExists("You already have created a wallet!") self.store.unlock(pwd)
[ "Create", "a", "new", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L147-L152
[ "def", "newWallet", "(", "self", ",", "pwd", ")", ":", "if", "self", ".", "created", "(", ")", ":", "raise", "WalletExists", "(", "\"You already have created a wallet!\"", ")", "self", ".", "store", ".", "unlock", "(", "pwd", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.addPrivateKey
Add a private key to the wallet database
graphenecommon/wallet.py
def addPrivateKey(self, wif): """ Add a private key to the wallet database """ try: pub = self.publickey_from_wif(wif) except Exception: raise InvalidWifError("Invalid Key format!") if str(pub) in self.store: raise KeyAlreadyInStoreException("Key already in the store") self.store.add(str(wif), str(pub))
def addPrivateKey(self, wif): """ Add a private key to the wallet database """ try: pub = self.publickey_from_wif(wif) except Exception: raise InvalidWifError("Invalid Key format!") if str(pub) in self.store: raise KeyAlreadyInStoreException("Key already in the store") self.store.add(str(wif), str(pub))
[ "Add", "a", "private", "key", "to", "the", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L154-L163
[ "def", "addPrivateKey", "(", "self", ",", "wif", ")", ":", "try", ":", "pub", "=", "self", ".", "publickey_from_wif", "(", "wif", ")", "except", "Exception", ":", "raise", "InvalidWifError", "(", "\"Invalid Key format!\"", ")", "if", "str", "(", "pub", ")", "in", "self", ".", "store", ":", "raise", "KeyAlreadyInStoreException", "(", "\"Key already in the store\"", ")", "self", ".", "store", ".", "add", "(", "str", "(", "wif", ")", ",", "str", "(", "pub", ")", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getPrivateKeyForPublicKey
Obtain the private key for a given public key :param str pub: Public Key
graphenecommon/wallet.py
def getPrivateKeyForPublicKey(self, pub): """ Obtain the private key for a given public key :param str pub: Public Key """ if str(pub) not in self.store: raise KeyNotFound return self.store.getPrivateKeyForPublicKey(str(pub))
def getPrivateKeyForPublicKey(self, pub): """ Obtain the private key for a given public key :param str pub: Public Key """ if str(pub) not in self.store: raise KeyNotFound return self.store.getPrivateKeyForPublicKey(str(pub))
[ "Obtain", "the", "private", "key", "for", "a", "given", "public", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L165-L172
[ "def", "getPrivateKeyForPublicKey", "(", "self", ",", "pub", ")", ":", "if", "str", "(", "pub", ")", "not", "in", "self", ".", "store", ":", "raise", "KeyNotFound", "return", "self", ".", "store", ".", "getPrivateKeyForPublicKey", "(", "str", "(", "pub", ")", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.removeAccount
Remove all keys associated with a given account
graphenecommon/wallet.py
def removeAccount(self, account): """ Remove all keys associated with a given account """ accounts = self.getAccounts() for a in accounts: if a["name"] == account: self.store.delete(a["pubkey"])
def removeAccount(self, account): """ Remove all keys associated with a given account """ accounts = self.getAccounts() for a in accounts: if a["name"] == account: self.store.delete(a["pubkey"])
[ "Remove", "all", "keys", "associated", "with", "a", "given", "account" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L179-L185
[ "def", "removeAccount", "(", "self", ",", "account", ")", ":", "accounts", "=", "self", ".", "getAccounts", "(", ")", "for", "a", "in", "accounts", ":", "if", "a", "[", "\"name\"", "]", "==", "account", ":", "self", ".", "store", ".", "delete", "(", "a", "[", "\"pubkey\"", "]", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getOwnerKeyForAccount
Obtain owner Private Key for an account from the wallet database
graphenecommon/wallet.py
def getOwnerKeyForAccount(self, name): """ Obtain owner Private Key for an account from the wallet database """ account = self.rpc.get_account(name) for authority in account["owner"]["key_auths"]: key = self.getPrivateKeyForPublicKey(authority[0]) if key: return key raise KeyNotFound
def getOwnerKeyForAccount(self, name): """ Obtain owner Private Key for an account from the wallet database """ account = self.rpc.get_account(name) for authority in account["owner"]["key_auths"]: key = self.getPrivateKeyForPublicKey(authority[0]) if key: return key raise KeyNotFound
[ "Obtain", "owner", "Private", "Key", "for", "an", "account", "from", "the", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L187-L195
[ "def", "getOwnerKeyForAccount", "(", "self", ",", "name", ")", ":", "account", "=", "self", ".", "rpc", ".", "get_account", "(", "name", ")", "for", "authority", "in", "account", "[", "\"owner\"", "]", "[", "\"key_auths\"", "]", ":", "key", "=", "self", ".", "getPrivateKeyForPublicKey", "(", "authority", "[", "0", "]", ")", "if", "key", ":", "return", "key", "raise", "KeyNotFound" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getMemoKeyForAccount
Obtain owner Memo Key for an account from the wallet database
graphenecommon/wallet.py
def getMemoKeyForAccount(self, name): """ Obtain owner Memo Key for an account from the wallet database """ account = self.rpc.get_account(name) key = self.getPrivateKeyForPublicKey(account["options"]["memo_key"]) if key: return key return False
def getMemoKeyForAccount(self, name): """ Obtain owner Memo Key for an account from the wallet database """ account = self.rpc.get_account(name) key = self.getPrivateKeyForPublicKey(account["options"]["memo_key"]) if key: return key return False
[ "Obtain", "owner", "Memo", "Key", "for", "an", "account", "from", "the", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L197-L204
[ "def", "getMemoKeyForAccount", "(", "self", ",", "name", ")", ":", "account", "=", "self", ".", "rpc", ".", "get_account", "(", "name", ")", "key", "=", "self", ".", "getPrivateKeyForPublicKey", "(", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ")", "if", "key", ":", "return", "key", "return", "False" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getActiveKeyForAccount
Obtain owner Active Key for an account from the wallet database
graphenecommon/wallet.py
def getActiveKeyForAccount(self, name): """ Obtain owner Active Key for an account from the wallet database """ account = self.rpc.get_account(name) for authority in account["active"]["key_auths"]: try: return self.getPrivateKeyForPublicKey(authority[0]) except Exception: pass return False
def getActiveKeyForAccount(self, name): """ Obtain owner Active Key for an account from the wallet database """ account = self.rpc.get_account(name) for authority in account["active"]["key_auths"]: try: return self.getPrivateKeyForPublicKey(authority[0]) except Exception: pass return False
[ "Obtain", "owner", "Active", "Key", "for", "an", "account", "from", "the", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L206-L215
[ "def", "getActiveKeyForAccount", "(", "self", ",", "name", ")", ":", "account", "=", "self", ".", "rpc", ".", "get_account", "(", "name", ")", "for", "authority", "in", "account", "[", "\"active\"", "]", "[", "\"key_auths\"", "]", ":", "try", ":", "return", "self", ".", "getPrivateKeyForPublicKey", "(", "authority", "[", "0", "]", ")", "except", "Exception", ":", "pass", "return", "False" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getAccountFromPrivateKey
Obtain account name from private key
graphenecommon/wallet.py
def getAccountFromPrivateKey(self, wif): """ Obtain account name from private key """ pub = self.publickey_from_wif(wif) return self.getAccountFromPublicKey(pub)
def getAccountFromPrivateKey(self, wif): """ Obtain account name from private key """ pub = self.publickey_from_wif(wif) return self.getAccountFromPublicKey(pub)
[ "Obtain", "account", "name", "from", "private", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L217-L221
[ "def", "getAccountFromPrivateKey", "(", "self", ",", "wif", ")", ":", "pub", "=", "self", ".", "publickey_from_wif", "(", "wif", ")", "return", "self", ".", "getAccountFromPublicKey", "(", "pub", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getAccountsFromPublicKey
Obtain all accounts associated with a public key
graphenecommon/wallet.py
def getAccountsFromPublicKey(self, pub): """ Obtain all accounts associated with a public key """ names = self.rpc.get_key_references([str(pub)])[0] for name in names: yield name
def getAccountsFromPublicKey(self, pub): """ Obtain all accounts associated with a public key """ names = self.rpc.get_key_references([str(pub)])[0] for name in names: yield name
[ "Obtain", "all", "accounts", "associated", "with", "a", "public", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L223-L228
[ "def", "getAccountsFromPublicKey", "(", "self", ",", "pub", ")", ":", "names", "=", "self", ".", "rpc", ".", "get_key_references", "(", "[", "str", "(", "pub", ")", "]", ")", "[", "0", "]", "for", "name", "in", "names", ":", "yield", "name" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getAccountFromPublicKey
Obtain the first account name from public key
graphenecommon/wallet.py
def getAccountFromPublicKey(self, pub): """ Obtain the first account name from public key """ # FIXME, this only returns the first associated key. # If the key is used by multiple accounts, this # will surely lead to undesired behavior names = list(self.getAccountsFromPublicKey(str(pub))) if names: return names[0]
def getAccountFromPublicKey(self, pub): """ Obtain the first account name from public key """ # FIXME, this only returns the first associated key. # If the key is used by multiple accounts, this # will surely lead to undesired behavior names = list(self.getAccountsFromPublicKey(str(pub))) if names: return names[0]
[ "Obtain", "the", "first", "account", "name", "from", "public", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L230-L238
[ "def", "getAccountFromPublicKey", "(", "self", ",", "pub", ")", ":", "# FIXME, this only returns the first associated key.", "# If the key is used by multiple accounts, this", "# will surely lead to undesired behavior", "names", "=", "list", "(", "self", ".", "getAccountsFromPublicKey", "(", "str", "(", "pub", ")", ")", ")", "if", "names", ":", "return", "names", "[", "0", "]" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getKeyType
Get key type
graphenecommon/wallet.py
def getKeyType(self, account, pub): """ Get key type """ for authority in ["owner", "active"]: for key in account[authority]["key_auths"]: if str(pub) == key[0]: return authority if str(pub) == account["options"]["memo_key"]: return "memo" return None
def getKeyType(self, account, pub): """ Get key type """ for authority in ["owner", "active"]: for key in account[authority]["key_auths"]: if str(pub) == key[0]: return authority if str(pub) == account["options"]["memo_key"]: return "memo" return None
[ "Get", "key", "type" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L249-L258
[ "def", "getKeyType", "(", "self", ",", "account", ",", "pub", ")", ":", "for", "authority", "in", "[", "\"owner\"", ",", "\"active\"", "]", ":", "for", "key", "in", "account", "[", "authority", "]", "[", "\"key_auths\"", "]", ":", "if", "str", "(", "pub", ")", "==", "key", "[", "0", "]", ":", "return", "authority", "if", "str", "(", "pub", ")", "==", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ":", "return", "\"memo\"", "return", "None" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getAccounts
Return all accounts installed in the wallet database
graphenecommon/wallet.py
def getAccounts(self): """ Return all accounts installed in the wallet database """ pubkeys = self.getPublicKeys() accounts = [] for pubkey in pubkeys: # Filter those keys not for our network if pubkey[: len(self.prefix)] == self.prefix: accounts.extend(self.getAccountsFromPublicKey(pubkey)) return accounts
def getAccounts(self): """ Return all accounts installed in the wallet database """ pubkeys = self.getPublicKeys() accounts = [] for pubkey in pubkeys: # Filter those keys not for our network if pubkey[: len(self.prefix)] == self.prefix: accounts.extend(self.getAccountsFromPublicKey(pubkey)) return accounts
[ "Return", "all", "accounts", "installed", "in", "the", "wallet", "database" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L260-L269
[ "def", "getAccounts", "(", "self", ")", ":", "pubkeys", "=", "self", ".", "getPublicKeys", "(", ")", "accounts", "=", "[", "]", "for", "pubkey", "in", "pubkeys", ":", "# Filter those keys not for our network", "if", "pubkey", "[", ":", "len", "(", "self", ".", "prefix", ")", "]", "==", "self", ".", "prefix", ":", "accounts", ".", "extend", "(", "self", ".", "getAccountsFromPublicKey", "(", "pubkey", ")", ")", "return", "accounts" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Wallet.getPublicKeys
Return all installed public keys :param bool current: If true, returns only keys for currently connected blockchain
graphenecommon/wallet.py
def getPublicKeys(self, current=False): """ Return all installed public keys :param bool current: If true, returns only keys for currently connected blockchain """ pubkeys = self.store.getPublicKeys() if not current: return pubkeys pubs = [] for pubkey in pubkeys: # Filter those keys not for our network if pubkey[: len(self.prefix)] == self.prefix: pubs.append(pubkey) return pubs
def getPublicKeys(self, current=False): """ Return all installed public keys :param bool current: If true, returns only keys for currently connected blockchain """ pubkeys = self.store.getPublicKeys() if not current: return pubkeys pubs = [] for pubkey in pubkeys: # Filter those keys not for our network if pubkey[: len(self.prefix)] == self.prefix: pubs.append(pubkey) return pubs
[ "Return", "all", "installed", "public", "keys" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/wallet.py#L271-L285
[ "def", "getPublicKeys", "(", "self", ",", "current", "=", "False", ")", ":", "pubkeys", "=", "self", ".", "store", ".", "getPublicKeys", "(", ")", "if", "not", "current", ":", "return", "pubkeys", "pubs", "=", "[", "]", "for", "pubkey", "in", "pubkeys", ":", "# Filter those keys not for our network", "if", "pubkey", "[", ":", "len", "(", "self", ".", "prefix", ")", "]", "==", "self", ".", "prefix", ":", "pubs", ".", "append", "(", "pubkey", ")", "return", "pubs" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Websocket.rpcexec
Execute a call by sending the payload :param json payload: Payload data :raises ValueError: if the server does not respond in proper JSON format
grapheneapi/websocket.py
def rpcexec(self, payload): """ Execute a call by sending the payload :param json payload: Payload data :raises ValueError: if the server does not respond in proper JSON format """ if not self.ws: # pragma: no cover self.connect() log.debug(json.dumps(payload)) # Mutex/Lock # We need to lock because we need to wait for websocket # response but don't want to allow other threads to send # requests (that might take less time) to disturb self.__lock.acquire() # Send over websocket try: self.ws.send(json.dumps(payload, ensure_ascii=False).encode("utf8")) # Receive from websocket ret = self.ws.recv() finally: # Release lock self.__lock.release() return ret
def rpcexec(self, payload): """ Execute a call by sending the payload :param json payload: Payload data :raises ValueError: if the server does not respond in proper JSON format """ if not self.ws: # pragma: no cover self.connect() log.debug(json.dumps(payload)) # Mutex/Lock # We need to lock because we need to wait for websocket # response but don't want to allow other threads to send # requests (that might take less time) to disturb self.__lock.acquire() # Send over websocket try: self.ws.send(json.dumps(payload, ensure_ascii=False).encode("utf8")) # Receive from websocket ret = self.ws.recv() finally: # Release lock self.__lock.release() return ret
[ "Execute", "a", "call", "by", "sending", "the", "payload" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/grapheneapi/websocket.py#L52-L80
[ "def", "rpcexec", "(", "self", ",", "payload", ")", ":", "if", "not", "self", ".", "ws", ":", "# pragma: no cover", "self", ".", "connect", "(", ")", "log", ".", "debug", "(", "json", ".", "dumps", "(", "payload", ")", ")", "# Mutex/Lock", "# We need to lock because we need to wait for websocket", "# response but don't want to allow other threads to send", "# requests (that might take less time) to disturb", "self", ".", "__lock", ".", "acquire", "(", ")", "# Send over websocket", "try", ":", "self", ".", "ws", ".", "send", "(", "json", ".", "dumps", "(", "payload", ",", "ensure_ascii", "=", "False", ")", ".", "encode", "(", "\"utf8\"", ")", ")", "# Receive from websocket", "ret", "=", "self", ".", "ws", ".", "recv", "(", ")", "finally", ":", "# Release lock", "self", ".", "__lock", ".", "release", "(", ")", "return", "ret" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Memo.unlock_wallet
Unlock the library internal wallet
graphenecommon/memo.py
def unlock_wallet(self, *args, **kwargs): """ Unlock the library internal wallet """ self.blockchain.wallet.unlock(*args, **kwargs) return self
def unlock_wallet(self, *args, **kwargs): """ Unlock the library internal wallet """ self.blockchain.wallet.unlock(*args, **kwargs) return self
[ "Unlock", "the", "library", "internal", "wallet" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/memo.py#L62-L66
[ "def", "unlock_wallet", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "blockchain", ".", "wallet", ".", "unlock", "(", "*", "args", ",", "*", "*", "kwargs", ")", "return", "self" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Memo.encrypt
Encrypt a memo :param str message: clear text memo message :returns: encrypted message :rtype: str
graphenecommon/memo.py
def encrypt(self, message): """ Encrypt a memo :param str message: clear text memo message :returns: encrypted message :rtype: str """ if not message: return None nonce = str(random.getrandbits(64)) try: memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey( self.from_account["options"]["memo_key"] ) except KeyNotFound: # if all fails, raise exception raise MissingKeyError( "Memo private key {} for {} could not be found".format( self.from_account["options"]["memo_key"], self.from_account["name"] ) ) if not memo_wif: raise MissingKeyError( "Memo key for %s missing!" % self.from_account["name"] ) if not hasattr(self, "chain_prefix"): self.chain_prefix = self.blockchain.prefix enc = memo.encode_memo( self.privatekey_class(memo_wif), self.publickey_class( self.to_account["options"]["memo_key"], prefix=self.chain_prefix ), nonce, message, ) return { "message": enc, "nonce": nonce, "from": self.from_account["options"]["memo_key"], "to": self.to_account["options"]["memo_key"], }
def encrypt(self, message): """ Encrypt a memo :param str message: clear text memo message :returns: encrypted message :rtype: str """ if not message: return None nonce = str(random.getrandbits(64)) try: memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey( self.from_account["options"]["memo_key"] ) except KeyNotFound: # if all fails, raise exception raise MissingKeyError( "Memo private key {} for {} could not be found".format( self.from_account["options"]["memo_key"], self.from_account["name"] ) ) if not memo_wif: raise MissingKeyError( "Memo key for %s missing!" % self.from_account["name"] ) if not hasattr(self, "chain_prefix"): self.chain_prefix = self.blockchain.prefix enc = memo.encode_memo( self.privatekey_class(memo_wif), self.publickey_class( self.to_account["options"]["memo_key"], prefix=self.chain_prefix ), nonce, message, ) return { "message": enc, "nonce": nonce, "from": self.from_account["options"]["memo_key"], "to": self.to_account["options"]["memo_key"], }
[ "Encrypt", "a", "memo" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/memo.py#L68-L112
[ "def", "encrypt", "(", "self", ",", "message", ")", ":", "if", "not", "message", ":", "return", "None", "nonce", "=", "str", "(", "random", ".", "getrandbits", "(", "64", ")", ")", "try", ":", "memo_wif", "=", "self", ".", "blockchain", ".", "wallet", ".", "getPrivateKeyForPublicKey", "(", "self", ".", "from_account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ")", "except", "KeyNotFound", ":", "# if all fails, raise exception", "raise", "MissingKeyError", "(", "\"Memo private key {} for {} could not be found\"", ".", "format", "(", "self", ".", "from_account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "self", ".", "from_account", "[", "\"name\"", "]", ")", ")", "if", "not", "memo_wif", ":", "raise", "MissingKeyError", "(", "\"Memo key for %s missing!\"", "%", "self", ".", "from_account", "[", "\"name\"", "]", ")", "if", "not", "hasattr", "(", "self", ",", "\"chain_prefix\"", ")", ":", "self", ".", "chain_prefix", "=", "self", ".", "blockchain", ".", "prefix", "enc", "=", "memo", ".", "encode_memo", "(", "self", ".", "privatekey_class", "(", "memo_wif", ")", ",", "self", ".", "publickey_class", "(", "self", ".", "to_account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "prefix", "=", "self", ".", "chain_prefix", ")", ",", "nonce", ",", "message", ",", ")", "return", "{", "\"message\"", ":", "enc", ",", "\"nonce\"", ":", "nonce", ",", "\"from\"", ":", "self", ".", "from_account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "\"to\"", ":", "self", ".", "to_account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "}" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
Memo.decrypt
Decrypt a message :param dict message: encrypted memo message :returns: decrypted message :rtype: str
graphenecommon/memo.py
def decrypt(self, message): """ Decrypt a message :param dict message: encrypted memo message :returns: decrypted message :rtype: str """ if not message: return None # We first try to decode assuming we received the memo try: memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(message["to"]) pubkey = message["from"] except KeyNotFound: try: # if that failed, we assume that we have sent the memo memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey( message["from"] ) pubkey = message["to"] except KeyNotFound: # if all fails, raise exception raise MissingKeyError( "None of the required memo keys are installed!" "Need any of {}".format([message["to"], message["from"]]) ) if not hasattr(self, "chain_prefix"): self.chain_prefix = self.blockchain.prefix return memo.decode_memo( self.privatekey_class(memo_wif), self.publickey_class(pubkey, prefix=self.chain_prefix), message.get("nonce"), message.get("message"), )
def decrypt(self, message): """ Decrypt a message :param dict message: encrypted memo message :returns: decrypted message :rtype: str """ if not message: return None # We first try to decode assuming we received the memo try: memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey(message["to"]) pubkey = message["from"] except KeyNotFound: try: # if that failed, we assume that we have sent the memo memo_wif = self.blockchain.wallet.getPrivateKeyForPublicKey( message["from"] ) pubkey = message["to"] except KeyNotFound: # if all fails, raise exception raise MissingKeyError( "None of the required memo keys are installed!" "Need any of {}".format([message["to"], message["from"]]) ) if not hasattr(self, "chain_prefix"): self.chain_prefix = self.blockchain.prefix return memo.decode_memo( self.privatekey_class(memo_wif), self.publickey_class(pubkey, prefix=self.chain_prefix), message.get("nonce"), message.get("message"), )
[ "Decrypt", "a", "message" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/memo.py#L114-L150
[ "def", "decrypt", "(", "self", ",", "message", ")", ":", "if", "not", "message", ":", "return", "None", "# We first try to decode assuming we received the memo", "try", ":", "memo_wif", "=", "self", ".", "blockchain", ".", "wallet", ".", "getPrivateKeyForPublicKey", "(", "message", "[", "\"to\"", "]", ")", "pubkey", "=", "message", "[", "\"from\"", "]", "except", "KeyNotFound", ":", "try", ":", "# if that failed, we assume that we have sent the memo", "memo_wif", "=", "self", ".", "blockchain", ".", "wallet", ".", "getPrivateKeyForPublicKey", "(", "message", "[", "\"from\"", "]", ")", "pubkey", "=", "message", "[", "\"to\"", "]", "except", "KeyNotFound", ":", "# if all fails, raise exception", "raise", "MissingKeyError", "(", "\"None of the required memo keys are installed!\"", "\"Need any of {}\"", ".", "format", "(", "[", "message", "[", "\"to\"", "]", ",", "message", "[", "\"from\"", "]", "]", ")", ")", "if", "not", "hasattr", "(", "self", ",", "\"chain_prefix\"", ")", ":", "self", ".", "chain_prefix", "=", "self", ".", "blockchain", ".", "prefix", "return", "memo", ".", "decode_memo", "(", "self", ".", "privatekey_class", "(", "memo_wif", ")", ",", "self", ".", "publickey_class", "(", "pubkey", ",", "prefix", "=", "self", ".", "chain_prefix", ")", ",", "message", ".", "get", "(", "\"nonce\"", ")", ",", "message", ".", "get", "(", "\"message\"", ")", ",", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
get_shared_secret
Derive the share secret between ``priv`` and ``pub`` :param `Base58` priv: Private Key :param `Base58` pub: Public Key :return: Shared secret :rtype: hex The shared secret is generated such that:: Pub(Alice) * Priv(Bob) = Pub(Bob) * Priv(Alice)
graphenebase/memo.py
def get_shared_secret(priv, pub): """ Derive the share secret between ``priv`` and ``pub`` :param `Base58` priv: Private Key :param `Base58` pub: Public Key :return: Shared secret :rtype: hex The shared secret is generated such that:: Pub(Alice) * Priv(Bob) = Pub(Bob) * Priv(Alice) """ pub_point = pub.point() priv_point = int(repr(priv), 16) res = pub_point * priv_point res_hex = "%032x" % res.x() # Zero padding res_hex = "0" * (64 - len(res_hex)) + res_hex return res_hex
def get_shared_secret(priv, pub): """ Derive the share secret between ``priv`` and ``pub`` :param `Base58` priv: Private Key :param `Base58` pub: Public Key :return: Shared secret :rtype: hex The shared secret is generated such that:: Pub(Alice) * Priv(Bob) = Pub(Bob) * Priv(Alice) """ pub_point = pub.point() priv_point = int(repr(priv), 16) res = pub_point * priv_point res_hex = "%032x" % res.x() # Zero padding res_hex = "0" * (64 - len(res_hex)) + res_hex return res_hex
[ "Derive", "the", "share", "secret", "between", "priv", "and", "pub" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/memo.py#L18-L37
[ "def", "get_shared_secret", "(", "priv", ",", "pub", ")", ":", "pub_point", "=", "pub", ".", "point", "(", ")", "priv_point", "=", "int", "(", "repr", "(", "priv", ")", ",", "16", ")", "res", "=", "pub_point", "*", "priv_point", "res_hex", "=", "\"%032x\"", "%", "res", ".", "x", "(", ")", "# Zero padding", "res_hex", "=", "\"0\"", "*", "(", "64", "-", "len", "(", "res_hex", ")", ")", "+", "res_hex", "return", "res_hex" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
init_aes
Initialize AES instance :param hex shared_secret: Shared Secret to use as encryption key :param int nonce: Random nonce :return: AES instance :rtype: AES
graphenebase/memo.py
def init_aes(shared_secret, nonce): """ Initialize AES instance :param hex shared_secret: Shared Secret to use as encryption key :param int nonce: Random nonce :return: AES instance :rtype: AES """ " Shared Secret " ss = hashlib.sha512(unhexlify(shared_secret)).digest() " Seed " seed = bytes(str(nonce), "ascii") + hexlify(ss) seed_digest = hexlify(hashlib.sha512(seed).digest()).decode("ascii") " AES " key = unhexlify(seed_digest[0:64]) iv = unhexlify(seed_digest[64:96]) return AES.new(key, AES.MODE_CBC, iv)
def init_aes(shared_secret, nonce): """ Initialize AES instance :param hex shared_secret: Shared Secret to use as encryption key :param int nonce: Random nonce :return: AES instance :rtype: AES """ " Shared Secret " ss = hashlib.sha512(unhexlify(shared_secret)).digest() " Seed " seed = bytes(str(nonce), "ascii") + hexlify(ss) seed_digest = hexlify(hashlib.sha512(seed).digest()).decode("ascii") " AES " key = unhexlify(seed_digest[0:64]) iv = unhexlify(seed_digest[64:96]) return AES.new(key, AES.MODE_CBC, iv)
[ "Initialize", "AES", "instance" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/memo.py#L40-L57
[ "def", "init_aes", "(", "shared_secret", ",", "nonce", ")", ":", "\" Shared Secret \"", "ss", "=", "hashlib", ".", "sha512", "(", "unhexlify", "(", "shared_secret", ")", ")", ".", "digest", "(", ")", "\" Seed \"", "seed", "=", "bytes", "(", "str", "(", "nonce", ")", ",", "\"ascii\"", ")", "+", "hexlify", "(", "ss", ")", "seed_digest", "=", "hexlify", "(", "hashlib", ".", "sha512", "(", "seed", ")", ".", "digest", "(", ")", ")", ".", "decode", "(", "\"ascii\"", ")", "\" AES \"", "key", "=", "unhexlify", "(", "seed_digest", "[", "0", ":", "64", "]", ")", "iv", "=", "unhexlify", "(", "seed_digest", "[", "64", ":", "96", "]", ")", "return", "AES", ".", "new", "(", "key", ",", "AES", ".", "MODE_CBC", ",", "iv", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
encode_memo
Encode a message with a shared secret between Alice and Bob :param PrivateKey priv: Private Key (of Alice) :param PublicKey pub: Public Key (of Bob) :param int nonce: Random nonce :param str message: Memo message :return: Encrypted message :rtype: hex
graphenebase/memo.py
def encode_memo(priv, pub, nonce, message): """ Encode a message with a shared secret between Alice and Bob :param PrivateKey priv: Private Key (of Alice) :param PublicKey pub: Public Key (of Bob) :param int nonce: Random nonce :param str message: Memo message :return: Encrypted message :rtype: hex """ shared_secret = get_shared_secret(priv, pub) aes = init_aes(shared_secret, nonce) " Checksum " raw = bytes(message, "utf8") checksum = hashlib.sha256(raw).digest() raw = checksum[0:4] + raw " Padding " raw = _pad(raw, 16) " Encryption " return hexlify(aes.encrypt(raw)).decode("ascii")
def encode_memo(priv, pub, nonce, message): """ Encode a message with a shared secret between Alice and Bob :param PrivateKey priv: Private Key (of Alice) :param PublicKey pub: Public Key (of Bob) :param int nonce: Random nonce :param str message: Memo message :return: Encrypted message :rtype: hex """ shared_secret = get_shared_secret(priv, pub) aes = init_aes(shared_secret, nonce) " Checksum " raw = bytes(message, "utf8") checksum = hashlib.sha256(raw).digest() raw = checksum[0:4] + raw " Padding " raw = _pad(raw, 16) " Encryption " return hexlify(aes.encrypt(raw)).decode("ascii")
[ "Encode", "a", "message", "with", "a", "shared", "secret", "between", "Alice", "and", "Bob" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/memo.py#L72-L92
[ "def", "encode_memo", "(", "priv", ",", "pub", ",", "nonce", ",", "message", ")", ":", "shared_secret", "=", "get_shared_secret", "(", "priv", ",", "pub", ")", "aes", "=", "init_aes", "(", "shared_secret", ",", "nonce", ")", "\" Checksum \"", "raw", "=", "bytes", "(", "message", ",", "\"utf8\"", ")", "checksum", "=", "hashlib", ".", "sha256", "(", "raw", ")", ".", "digest", "(", ")", "raw", "=", "checksum", "[", "0", ":", "4", "]", "+", "raw", "\" Padding \"", "raw", "=", "_pad", "(", "raw", ",", "16", ")", "\" Encryption \"", "return", "hexlify", "(", "aes", ".", "encrypt", "(", "raw", ")", ")", ".", "decode", "(", "\"ascii\"", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
decode_memo
Decode a message with a shared secret between Alice and Bob :param PrivateKey priv: Private Key (of Bob) :param PublicKey pub: Public Key (of Alice) :param int nonce: Nonce used for Encryption :param bytes message: Encrypted Memo message :return: Decrypted message :rtype: str :raise ValueError: if message cannot be decoded as valid UTF-8 string
graphenebase/memo.py
def decode_memo(priv, pub, nonce, message): """ Decode a message with a shared secret between Alice and Bob :param PrivateKey priv: Private Key (of Bob) :param PublicKey pub: Public Key (of Alice) :param int nonce: Nonce used for Encryption :param bytes message: Encrypted Memo message :return: Decrypted message :rtype: str :raise ValueError: if message cannot be decoded as valid UTF-8 string """ shared_secret = get_shared_secret(priv, pub) aes = init_aes(shared_secret, nonce) " Encryption " raw = bytes(message, "ascii") cleartext = aes.decrypt(unhexlify(raw)) " Checksum " checksum = cleartext[0:4] message = cleartext[4:] message = _unpad(message, 16) " Verify checksum " check = hashlib.sha256(message).digest()[0:4] if check != checksum: # pragma: no cover raise ValueError("checksum verification failure") return message.decode("utf8")
def decode_memo(priv, pub, nonce, message): """ Decode a message with a shared secret between Alice and Bob :param PrivateKey priv: Private Key (of Bob) :param PublicKey pub: Public Key (of Alice) :param int nonce: Nonce used for Encryption :param bytes message: Encrypted Memo message :return: Decrypted message :rtype: str :raise ValueError: if message cannot be decoded as valid UTF-8 string """ shared_secret = get_shared_secret(priv, pub) aes = init_aes(shared_secret, nonce) " Encryption " raw = bytes(message, "ascii") cleartext = aes.decrypt(unhexlify(raw)) " Checksum " checksum = cleartext[0:4] message = cleartext[4:] message = _unpad(message, 16) " Verify checksum " check = hashlib.sha256(message).digest()[0:4] if check != checksum: # pragma: no cover raise ValueError("checksum verification failure") return message.decode("utf8")
[ "Decode", "a", "message", "with", "a", "shared", "secret", "between", "Alice", "and", "Bob" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenebase/memo.py#L95-L121
[ "def", "decode_memo", "(", "priv", ",", "pub", ",", "nonce", ",", "message", ")", ":", "shared_secret", "=", "get_shared_secret", "(", "priv", ",", "pub", ")", "aes", "=", "init_aes", "(", "shared_secret", ",", "nonce", ")", "\" Encryption \"", "raw", "=", "bytes", "(", "message", ",", "\"ascii\"", ")", "cleartext", "=", "aes", ".", "decrypt", "(", "unhexlify", "(", "raw", ")", ")", "\" Checksum \"", "checksum", "=", "cleartext", "[", "0", ":", "4", "]", "message", "=", "cleartext", "[", "4", ":", "]", "message", "=", "_unpad", "(", "message", ",", "16", ")", "\" Verify checksum \"", "check", "=", "hashlib", ".", "sha256", "(", "message", ")", ".", "digest", "(", ")", "[", "0", ":", "4", "]", "if", "check", "!=", "checksum", ":", "# pragma: no cover", "raise", "ValueError", "(", "\"checksum verification failure\"", ")", "return", "message", ".", "decode", "(", "\"utf8\"", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
MessageV1.sign
Sign a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :raises ValueError: If not account for signing is provided :returns: the signed message encapsulated in a known format
graphenecommon/message.py
def sign(self, account=None, **kwargs): """ Sign a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :raises ValueError: If not account for signing is provided :returns: the signed message encapsulated in a known format """ if not account: if "default_account" in self.blockchain.config: account = self.blockchain.config["default_account"] if not account: raise ValueError("You need to provide an account") # Data for message account = self.account_class(account, blockchain_instance=self.blockchain) info = self.blockchain.info() meta = dict( timestamp=info["time"], block=info["head_block_number"], memokey=account["options"]["memo_key"], account=account["name"], ) # wif key wif = self.blockchain.wallet.getPrivateKeyForPublicKey( account["options"]["memo_key"] ) # We strip the message here so we know for sure there are no trailing # whitespaces or returns message = self.message.strip() enc_message = self.SIGNED_MESSAGE_META.format(**locals()) # signature signature = hexlify(sign_message(enc_message, wif)).decode("ascii") self.signed_by_account = account self.signed_by_name = account["name"] self.meta = meta self.plain_message = message return self.SIGNED_MESSAGE_ENCAPSULATED.format( MESSAGE_SPLIT=self.MESSAGE_SPLIT, **locals() )
def sign(self, account=None, **kwargs): """ Sign a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :raises ValueError: If not account for signing is provided :returns: the signed message encapsulated in a known format """ if not account: if "default_account" in self.blockchain.config: account = self.blockchain.config["default_account"] if not account: raise ValueError("You need to provide an account") # Data for message account = self.account_class(account, blockchain_instance=self.blockchain) info = self.blockchain.info() meta = dict( timestamp=info["time"], block=info["head_block_number"], memokey=account["options"]["memo_key"], account=account["name"], ) # wif key wif = self.blockchain.wallet.getPrivateKeyForPublicKey( account["options"]["memo_key"] ) # We strip the message here so we know for sure there are no trailing # whitespaces or returns message = self.message.strip() enc_message = self.SIGNED_MESSAGE_META.format(**locals()) # signature signature = hexlify(sign_message(enc_message, wif)).decode("ascii") self.signed_by_account = account self.signed_by_name = account["name"] self.meta = meta self.plain_message = message return self.SIGNED_MESSAGE_ENCAPSULATED.format( MESSAGE_SPLIT=self.MESSAGE_SPLIT, **locals() )
[ "Sign", "a", "message", "with", "an", "account", "s", "memo", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/message.py#L64-L110
[ "def", "sign", "(", "self", ",", "account", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "not", "account", ":", "if", "\"default_account\"", "in", "self", ".", "blockchain", ".", "config", ":", "account", "=", "self", ".", "blockchain", ".", "config", "[", "\"default_account\"", "]", "if", "not", "account", ":", "raise", "ValueError", "(", "\"You need to provide an account\"", ")", "# Data for message", "account", "=", "self", ".", "account_class", "(", "account", ",", "blockchain_instance", "=", "self", ".", "blockchain", ")", "info", "=", "self", ".", "blockchain", ".", "info", "(", ")", "meta", "=", "dict", "(", "timestamp", "=", "info", "[", "\"time\"", "]", ",", "block", "=", "info", "[", "\"head_block_number\"", "]", ",", "memokey", "=", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "account", "=", "account", "[", "\"name\"", "]", ",", ")", "# wif key", "wif", "=", "self", ".", "blockchain", ".", "wallet", ".", "getPrivateKeyForPublicKey", "(", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ")", "# We strip the message here so we know for sure there are no trailing", "# whitespaces or returns", "message", "=", "self", ".", "message", ".", "strip", "(", ")", "enc_message", "=", "self", ".", "SIGNED_MESSAGE_META", ".", "format", "(", "*", "*", "locals", "(", ")", ")", "# signature", "signature", "=", "hexlify", "(", "sign_message", "(", "enc_message", ",", "wif", ")", ")", ".", "decode", "(", "\"ascii\"", ")", "self", ".", "signed_by_account", "=", "account", "self", ".", "signed_by_name", "=", "account", "[", "\"name\"", "]", "self", ".", "meta", "=", "meta", "self", ".", "plain_message", "=", "message", "return", "self", ".", "SIGNED_MESSAGE_ENCAPSULATED", ".", "format", "(", "MESSAGE_SPLIT", "=", "self", ".", "MESSAGE_SPLIT", ",", "*", "*", "locals", "(", ")", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
MessageV1.verify
Verify a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :returns: True if the message is verified successfully :raises InvalidMessageSignature if the signature is not ok
graphenecommon/message.py
def verify(self, **kwargs): """ Verify a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :returns: True if the message is verified successfully :raises InvalidMessageSignature if the signature is not ok """ # Split message into its parts parts = re.split("|".join(self.MESSAGE_SPLIT), self.message) parts = [x for x in parts if x.strip()] assert len(parts) > 2, "Incorrect number of message parts" # Strip away all whitespaces before and after the message message = parts[0].strip() signature = parts[2].strip() # Parse the meta data meta = dict(re.findall(r"(\S+)=(.*)", parts[1])) log.info("Message is: {}".format(message)) log.info("Meta is: {}".format(json.dumps(meta))) log.info("Signature is: {}".format(signature)) # Ensure we have all the data in meta assert "account" in meta, "No 'account' could be found in meta data" assert "memokey" in meta, "No 'memokey' could be found in meta data" assert "block" in meta, "No 'block' could be found in meta data" assert "timestamp" in meta, "No 'timestamp' could be found in meta data" account_name = meta.get("account").strip() memo_key = meta["memokey"].strip() try: self.publickey_class(memo_key, prefix=self.blockchain.prefix) except Exception: raise InvalidMemoKeyException("The memo key in the message is invalid") # Load account from blockchain try: account = self.account_class( account_name, blockchain_instance=self.blockchain ) except AccountDoesNotExistsException: raise AccountDoesNotExistsException( "Could not find account {}. Are you connected to the right chain?".format( account_name ) ) # Test if memo key is the same as on the blockchain if not account["options"]["memo_key"] == memo_key: raise WrongMemoKey( "Memo Key of account {} on the Blockchain ".format(account["name"]) + "differs from memo key in the message: {} != {}".format( account["options"]["memo_key"], memo_key ) ) # Reformat message enc_message = self.SIGNED_MESSAGE_META.format(**locals()) # Verify Signature pubkey = verify_message(enc_message, unhexlify(signature)) # Verify pubky pk = self.publickey_class( hexlify(pubkey).decode("ascii"), prefix=self.blockchain.prefix ) if format(pk, self.blockchain.prefix) != memo_key: raise InvalidMessageSignature("The signature doesn't match the memo key") self.signed_by_account = account self.signed_by_name = account["name"] self.meta = meta self.plain_message = message return True
def verify(self, **kwargs): """ Verify a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :returns: True if the message is verified successfully :raises InvalidMessageSignature if the signature is not ok """ # Split message into its parts parts = re.split("|".join(self.MESSAGE_SPLIT), self.message) parts = [x for x in parts if x.strip()] assert len(parts) > 2, "Incorrect number of message parts" # Strip away all whitespaces before and after the message message = parts[0].strip() signature = parts[2].strip() # Parse the meta data meta = dict(re.findall(r"(\S+)=(.*)", parts[1])) log.info("Message is: {}".format(message)) log.info("Meta is: {}".format(json.dumps(meta))) log.info("Signature is: {}".format(signature)) # Ensure we have all the data in meta assert "account" in meta, "No 'account' could be found in meta data" assert "memokey" in meta, "No 'memokey' could be found in meta data" assert "block" in meta, "No 'block' could be found in meta data" assert "timestamp" in meta, "No 'timestamp' could be found in meta data" account_name = meta.get("account").strip() memo_key = meta["memokey"].strip() try: self.publickey_class(memo_key, prefix=self.blockchain.prefix) except Exception: raise InvalidMemoKeyException("The memo key in the message is invalid") # Load account from blockchain try: account = self.account_class( account_name, blockchain_instance=self.blockchain ) except AccountDoesNotExistsException: raise AccountDoesNotExistsException( "Could not find account {}. Are you connected to the right chain?".format( account_name ) ) # Test if memo key is the same as on the blockchain if not account["options"]["memo_key"] == memo_key: raise WrongMemoKey( "Memo Key of account {} on the Blockchain ".format(account["name"]) + "differs from memo key in the message: {} != {}".format( account["options"]["memo_key"], memo_key ) ) # Reformat message enc_message = self.SIGNED_MESSAGE_META.format(**locals()) # Verify Signature pubkey = verify_message(enc_message, unhexlify(signature)) # Verify pubky pk = self.publickey_class( hexlify(pubkey).decode("ascii"), prefix=self.blockchain.prefix ) if format(pk, self.blockchain.prefix) != memo_key: raise InvalidMessageSignature("The signature doesn't match the memo key") self.signed_by_account = account self.signed_by_name = account["name"] self.meta = meta self.plain_message = message return True
[ "Verify", "a", "message", "with", "an", "account", "s", "memo", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/message.py#L112-L190
[ "def", "verify", "(", "self", ",", "*", "*", "kwargs", ")", ":", "# Split message into its parts", "parts", "=", "re", ".", "split", "(", "\"|\"", ".", "join", "(", "self", ".", "MESSAGE_SPLIT", ")", ",", "self", ".", "message", ")", "parts", "=", "[", "x", "for", "x", "in", "parts", "if", "x", ".", "strip", "(", ")", "]", "assert", "len", "(", "parts", ")", ">", "2", ",", "\"Incorrect number of message parts\"", "# Strip away all whitespaces before and after the message", "message", "=", "parts", "[", "0", "]", ".", "strip", "(", ")", "signature", "=", "parts", "[", "2", "]", ".", "strip", "(", ")", "# Parse the meta data", "meta", "=", "dict", "(", "re", ".", "findall", "(", "r\"(\\S+)=(.*)\"", ",", "parts", "[", "1", "]", ")", ")", "log", ".", "info", "(", "\"Message is: {}\"", ".", "format", "(", "message", ")", ")", "log", ".", "info", "(", "\"Meta is: {}\"", ".", "format", "(", "json", ".", "dumps", "(", "meta", ")", ")", ")", "log", ".", "info", "(", "\"Signature is: {}\"", ".", "format", "(", "signature", ")", ")", "# Ensure we have all the data in meta", "assert", "\"account\"", "in", "meta", ",", "\"No 'account' could be found in meta data\"", "assert", "\"memokey\"", "in", "meta", ",", "\"No 'memokey' could be found in meta data\"", "assert", "\"block\"", "in", "meta", ",", "\"No 'block' could be found in meta data\"", "assert", "\"timestamp\"", "in", "meta", ",", "\"No 'timestamp' could be found in meta data\"", "account_name", "=", "meta", ".", "get", "(", "\"account\"", ")", ".", "strip", "(", ")", "memo_key", "=", "meta", "[", "\"memokey\"", "]", ".", "strip", "(", ")", "try", ":", "self", ".", "publickey_class", "(", "memo_key", ",", "prefix", "=", "self", ".", "blockchain", ".", "prefix", ")", "except", "Exception", ":", "raise", "InvalidMemoKeyException", "(", "\"The memo key in the message is invalid\"", ")", "# Load account from blockchain", "try", ":", "account", "=", "self", ".", "account_class", "(", "account_name", ",", "blockchain_instance", "=", "self", ".", "blockchain", ")", "except", "AccountDoesNotExistsException", ":", "raise", "AccountDoesNotExistsException", "(", "\"Could not find account {}. Are you connected to the right chain?\"", ".", "format", "(", "account_name", ")", ")", "# Test if memo key is the same as on the blockchain", "if", "not", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", "==", "memo_key", ":", "raise", "WrongMemoKey", "(", "\"Memo Key of account {} on the Blockchain \"", ".", "format", "(", "account", "[", "\"name\"", "]", ")", "+", "\"differs from memo key in the message: {} != {}\"", ".", "format", "(", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "memo_key", ")", ")", "# Reformat message", "enc_message", "=", "self", ".", "SIGNED_MESSAGE_META", ".", "format", "(", "*", "*", "locals", "(", ")", ")", "# Verify Signature", "pubkey", "=", "verify_message", "(", "enc_message", ",", "unhexlify", "(", "signature", ")", ")", "# Verify pubky", "pk", "=", "self", ".", "publickey_class", "(", "hexlify", "(", "pubkey", ")", ".", "decode", "(", "\"ascii\"", ")", ",", "prefix", "=", "self", ".", "blockchain", ".", "prefix", ")", "if", "format", "(", "pk", ",", "self", ".", "blockchain", ".", "prefix", ")", "!=", "memo_key", ":", "raise", "InvalidMessageSignature", "(", "\"The signature doesn't match the memo key\"", ")", "self", ".", "signed_by_account", "=", "account", "self", ".", "signed_by_name", "=", "account", "[", "\"name\"", "]", "self", ".", "meta", "=", "meta", "self", ".", "plain_message", "=", "message", "return", "True" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
MessageV2.sign
Sign a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :raises ValueError: If not account for signing is provided :returns: the signed message encapsulated in a known format
graphenecommon/message.py
def sign(self, account=None, **kwargs): """ Sign a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :raises ValueError: If not account for signing is provided :returns: the signed message encapsulated in a known format """ if not account: if "default_account" in self.blockchain.config: account = self.blockchain.config["default_account"] if not account: raise ValueError("You need to provide an account") # Data for message account = self.account_class(account, blockchain_instance=self.blockchain) # wif key wif = self.blockchain.wallet.getPrivateKeyForPublicKey( account["options"]["memo_key"] ) payload = [ "from", account["name"], "key", account["options"]["memo_key"], "time", str(datetime.utcnow()), "text", self.message, ] enc_message = json.dumps(payload, separators=(",", ":")) # signature signature = hexlify(sign_message(enc_message, wif)).decode("ascii") return dict(signed=enc_message, payload=payload, signature=signature)
def sign(self, account=None, **kwargs): """ Sign a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :raises ValueError: If not account for signing is provided :returns: the signed message encapsulated in a known format """ if not account: if "default_account" in self.blockchain.config: account = self.blockchain.config["default_account"] if not account: raise ValueError("You need to provide an account") # Data for message account = self.account_class(account, blockchain_instance=self.blockchain) # wif key wif = self.blockchain.wallet.getPrivateKeyForPublicKey( account["options"]["memo_key"] ) payload = [ "from", account["name"], "key", account["options"]["memo_key"], "time", str(datetime.utcnow()), "text", self.message, ] enc_message = json.dumps(payload, separators=(",", ":")) # signature signature = hexlify(sign_message(enc_message, wif)).decode("ascii") return dict(signed=enc_message, payload=payload, signature=signature)
[ "Sign", "a", "message", "with", "an", "account", "s", "memo", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/message.py#L208-L246
[ "def", "sign", "(", "self", ",", "account", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "not", "account", ":", "if", "\"default_account\"", "in", "self", ".", "blockchain", ".", "config", ":", "account", "=", "self", ".", "blockchain", ".", "config", "[", "\"default_account\"", "]", "if", "not", "account", ":", "raise", "ValueError", "(", "\"You need to provide an account\"", ")", "# Data for message", "account", "=", "self", ".", "account_class", "(", "account", ",", "blockchain_instance", "=", "self", ".", "blockchain", ")", "# wif key", "wif", "=", "self", ".", "blockchain", ".", "wallet", ".", "getPrivateKeyForPublicKey", "(", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ")", "payload", "=", "[", "\"from\"", ",", "account", "[", "\"name\"", "]", ",", "\"key\"", ",", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "\"time\"", ",", "str", "(", "datetime", ".", "utcnow", "(", ")", ")", ",", "\"text\"", ",", "self", ".", "message", ",", "]", "enc_message", "=", "json", ".", "dumps", "(", "payload", ",", "separators", "=", "(", "\",\"", ",", "\":\"", ")", ")", "# signature", "signature", "=", "hexlify", "(", "sign_message", "(", "enc_message", ",", "wif", ")", ")", ".", "decode", "(", "\"ascii\"", ")", "return", "dict", "(", "signed", "=", "enc_message", ",", "payload", "=", "payload", ",", "signature", "=", "signature", ")" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
MessageV2.verify
Verify a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :returns: True if the message is verified successfully :raises InvalidMessageSignature if the signature is not ok
graphenecommon/message.py
def verify(self, **kwargs): """ Verify a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :returns: True if the message is verified successfully :raises InvalidMessageSignature if the signature is not ok """ if not isinstance(self.message, dict): try: self.message = json.loads(self.message) except Exception: raise ValueError("Message must be valid JSON") payload = self.message.get("payload") assert payload, "Missing payload" payload_dict = {k[0]: k[1] for k in zip(payload[::2], payload[1::2])} signature = self.message.get("signature") account_name = payload_dict.get("from").strip() memo_key = payload_dict.get("key").strip() assert account_name, "Missing account name 'from'" assert memo_key, "missing 'key'" try: self.publickey_class(memo_key, prefix=self.blockchain.prefix) except Exception: raise InvalidMemoKeyException("The memo key in the message is invalid") # Load account from blockchain try: account = self.account_class( account_name, blockchain_instance=self.blockchain ) except AccountDoesNotExistsException: raise AccountDoesNotExistsException( "Could not find account {}. Are you connected to the right chain?".format( account_name ) ) # Test if memo key is the same as on the blockchain if not account["options"]["memo_key"] == memo_key: raise WrongMemoKey( "Memo Key of account {} on the Blockchain ".format(account["name"]) + "differs from memo key in the message: {} != {}".format( account["options"]["memo_key"], memo_key ) ) # Ensure payload and signed match signed_target = json.dumps(self.message.get("payload"), separators=(",", ":")) signed_actual = self.message.get("signed") assert ( signed_target == signed_actual ), "payload doesn't match signed message: \n{}\n{}".format( signed_target, signed_actual ) # Reformat message enc_message = self.message.get("signed") # Verify Signature pubkey = verify_message(enc_message, unhexlify(signature)) # Verify pubky pk = self.publickey_class( hexlify(pubkey).decode("ascii"), prefix=self.blockchain.prefix ) if format(pk, self.blockchain.prefix) != memo_key: raise InvalidMessageSignature("The signature doesn't match the memo key") self.signed_by_account = account self.signed_by_name = account["name"] self.plain_message = payload_dict.get("text") return True
def verify(self, **kwargs): """ Verify a message with an account's memo key :param str account: (optional) the account that owns the bet (defaults to ``default_account``) :returns: True if the message is verified successfully :raises InvalidMessageSignature if the signature is not ok """ if not isinstance(self.message, dict): try: self.message = json.loads(self.message) except Exception: raise ValueError("Message must be valid JSON") payload = self.message.get("payload") assert payload, "Missing payload" payload_dict = {k[0]: k[1] for k in zip(payload[::2], payload[1::2])} signature = self.message.get("signature") account_name = payload_dict.get("from").strip() memo_key = payload_dict.get("key").strip() assert account_name, "Missing account name 'from'" assert memo_key, "missing 'key'" try: self.publickey_class(memo_key, prefix=self.blockchain.prefix) except Exception: raise InvalidMemoKeyException("The memo key in the message is invalid") # Load account from blockchain try: account = self.account_class( account_name, blockchain_instance=self.blockchain ) except AccountDoesNotExistsException: raise AccountDoesNotExistsException( "Could not find account {}. Are you connected to the right chain?".format( account_name ) ) # Test if memo key is the same as on the blockchain if not account["options"]["memo_key"] == memo_key: raise WrongMemoKey( "Memo Key of account {} on the Blockchain ".format(account["name"]) + "differs from memo key in the message: {} != {}".format( account["options"]["memo_key"], memo_key ) ) # Ensure payload and signed match signed_target = json.dumps(self.message.get("payload"), separators=(",", ":")) signed_actual = self.message.get("signed") assert ( signed_target == signed_actual ), "payload doesn't match signed message: \n{}\n{}".format( signed_target, signed_actual ) # Reformat message enc_message = self.message.get("signed") # Verify Signature pubkey = verify_message(enc_message, unhexlify(signature)) # Verify pubky pk = self.publickey_class( hexlify(pubkey).decode("ascii"), prefix=self.blockchain.prefix ) if format(pk, self.blockchain.prefix) != memo_key: raise InvalidMessageSignature("The signature doesn't match the memo key") self.signed_by_account = account self.signed_by_name = account["name"] self.plain_message = payload_dict.get("text") return True
[ "Verify", "a", "message", "with", "an", "account", "s", "memo", "key" ]
xeroc/python-graphenelib
python
https://github.com/xeroc/python-graphenelib/blob/8bb5396bc79998ee424cf3813af478304173f3a6/graphenecommon/message.py#L248-L326
[ "def", "verify", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "not", "isinstance", "(", "self", ".", "message", ",", "dict", ")", ":", "try", ":", "self", ".", "message", "=", "json", ".", "loads", "(", "self", ".", "message", ")", "except", "Exception", ":", "raise", "ValueError", "(", "\"Message must be valid JSON\"", ")", "payload", "=", "self", ".", "message", ".", "get", "(", "\"payload\"", ")", "assert", "payload", ",", "\"Missing payload\"", "payload_dict", "=", "{", "k", "[", "0", "]", ":", "k", "[", "1", "]", "for", "k", "in", "zip", "(", "payload", "[", ":", ":", "2", "]", ",", "payload", "[", "1", ":", ":", "2", "]", ")", "}", "signature", "=", "self", ".", "message", ".", "get", "(", "\"signature\"", ")", "account_name", "=", "payload_dict", ".", "get", "(", "\"from\"", ")", ".", "strip", "(", ")", "memo_key", "=", "payload_dict", ".", "get", "(", "\"key\"", ")", ".", "strip", "(", ")", "assert", "account_name", ",", "\"Missing account name 'from'\"", "assert", "memo_key", ",", "\"missing 'key'\"", "try", ":", "self", ".", "publickey_class", "(", "memo_key", ",", "prefix", "=", "self", ".", "blockchain", ".", "prefix", ")", "except", "Exception", ":", "raise", "InvalidMemoKeyException", "(", "\"The memo key in the message is invalid\"", ")", "# Load account from blockchain", "try", ":", "account", "=", "self", ".", "account_class", "(", "account_name", ",", "blockchain_instance", "=", "self", ".", "blockchain", ")", "except", "AccountDoesNotExistsException", ":", "raise", "AccountDoesNotExistsException", "(", "\"Could not find account {}. Are you connected to the right chain?\"", ".", "format", "(", "account_name", ")", ")", "# Test if memo key is the same as on the blockchain", "if", "not", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", "==", "memo_key", ":", "raise", "WrongMemoKey", "(", "\"Memo Key of account {} on the Blockchain \"", ".", "format", "(", "account", "[", "\"name\"", "]", ")", "+", "\"differs from memo key in the message: {} != {}\"", ".", "format", "(", "account", "[", "\"options\"", "]", "[", "\"memo_key\"", "]", ",", "memo_key", ")", ")", "# Ensure payload and signed match", "signed_target", "=", "json", ".", "dumps", "(", "self", ".", "message", ".", "get", "(", "\"payload\"", ")", ",", "separators", "=", "(", "\",\"", ",", "\":\"", ")", ")", "signed_actual", "=", "self", ".", "message", ".", "get", "(", "\"signed\"", ")", "assert", "(", "signed_target", "==", "signed_actual", ")", ",", "\"payload doesn't match signed message: \\n{}\\n{}\"", ".", "format", "(", "signed_target", ",", "signed_actual", ")", "# Reformat message", "enc_message", "=", "self", ".", "message", ".", "get", "(", "\"signed\"", ")", "# Verify Signature", "pubkey", "=", "verify_message", "(", "enc_message", ",", "unhexlify", "(", "signature", ")", ")", "# Verify pubky", "pk", "=", "self", ".", "publickey_class", "(", "hexlify", "(", "pubkey", ")", ".", "decode", "(", "\"ascii\"", ")", ",", "prefix", "=", "self", ".", "blockchain", ".", "prefix", ")", "if", "format", "(", "pk", ",", "self", ".", "blockchain", ".", "prefix", ")", "!=", "memo_key", ":", "raise", "InvalidMessageSignature", "(", "\"The signature doesn't match the memo key\"", ")", "self", ".", "signed_by_account", "=", "account", "self", ".", "signed_by_name", "=", "account", "[", "\"name\"", "]", "self", ".", "plain_message", "=", "payload_dict", ".", "get", "(", "\"text\"", ")", "return", "True" ]
8bb5396bc79998ee424cf3813af478304173f3a6
valid
env
Verify IPMI environment
modules/cij/ipmi.py
def env(): """Verify IPMI environment""" ipmi = cij.env_to_dict(PREFIX, REQUIRED) if ipmi is None: ipmi["USER"] = "admin" ipmi["PASS"] = "admin" ipmi["HOST"] = "localhost" ipmi["PORT"] = "623" cij.info("ipmi.env: USER: %s, PASS: %s, HOST: %s, PORT: %s" % ( ipmi["USER"], ipmi["PASS"], ipmi["HOST"], ipmi["PORT"] )) cij.env_export(PREFIX, EXPORTED, ipmi) return 0
def env(): """Verify IPMI environment""" ipmi = cij.env_to_dict(PREFIX, REQUIRED) if ipmi is None: ipmi["USER"] = "admin" ipmi["PASS"] = "admin" ipmi["HOST"] = "localhost" ipmi["PORT"] = "623" cij.info("ipmi.env: USER: %s, PASS: %s, HOST: %s, PORT: %s" % ( ipmi["USER"], ipmi["PASS"], ipmi["HOST"], ipmi["PORT"] )) cij.env_export(PREFIX, EXPORTED, ipmi) return 0
[ "Verify", "IPMI", "environment" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/ipmi.py#L27-L43
[ "def", "env", "(", ")", ":", "ipmi", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "REQUIRED", ")", "if", "ipmi", "is", "None", ":", "ipmi", "[", "\"USER\"", "]", "=", "\"admin\"", "ipmi", "[", "\"PASS\"", "]", "=", "\"admin\"", "ipmi", "[", "\"HOST\"", "]", "=", "\"localhost\"", "ipmi", "[", "\"PORT\"", "]", "=", "\"623\"", "cij", ".", "info", "(", "\"ipmi.env: USER: %s, PASS: %s, HOST: %s, PORT: %s\"", "%", "(", "ipmi", "[", "\"USER\"", "]", ",", "ipmi", "[", "\"PASS\"", "]", ",", "ipmi", "[", "\"HOST\"", "]", ",", "ipmi", "[", "\"PORT\"", "]", ")", ")", "cij", ".", "env_export", "(", "PREFIX", ",", "EXPORTED", ",", "ipmi", ")", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
cmd
Send IPMI 'command' via ipmitool
modules/cij/ipmi.py
def cmd(command): """Send IPMI 'command' via ipmitool""" env() ipmi = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) command = "ipmitool -U %s -P %s -H %s -p %s %s" % ( ipmi["USER"], ipmi["PASS"], ipmi["HOST"], ipmi["PORT"], command) cij.info("ipmi.command: %s" % command) return cij.util.execute(command, shell=True, echo=True)
def cmd(command): """Send IPMI 'command' via ipmitool""" env() ipmi = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) command = "ipmitool -U %s -P %s -H %s -p %s %s" % ( ipmi["USER"], ipmi["PASS"], ipmi["HOST"], ipmi["PORT"], command) cij.info("ipmi.command: %s" % command) return cij.util.execute(command, shell=True, echo=True)
[ "Send", "IPMI", "command", "via", "ipmitool" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/ipmi.py#L46-L57
[ "def", "cmd", "(", "command", ")", ":", "env", "(", ")", "ipmi", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "EXPORTED", "+", "REQUIRED", ")", "command", "=", "\"ipmitool -U %s -P %s -H %s -p %s %s\"", "%", "(", "ipmi", "[", "\"USER\"", "]", ",", "ipmi", "[", "\"PASS\"", "]", ",", "ipmi", "[", "\"HOST\"", "]", ",", "ipmi", "[", "\"PORT\"", "]", ",", "command", ")", "cij", ".", "info", "(", "\"ipmi.command: %s\"", "%", "command", ")", "return", "cij", ".", "util", ".", "execute", "(", "command", ",", "shell", "=", "True", ",", "echo", "=", "True", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
regex_find
Find the given 'pattern' in 'content
modules/cij/util.py
def regex_find(pattern, content): """Find the given 'pattern' in 'content'""" find = re.findall(pattern, content) if not find: cij.err("pattern <%r> is invalid, no matches!" % pattern) cij.err("content: %r" % content) return '' if len(find) >= 2: cij.err("pattern <%r> is too simple, matched more than 2!" % pattern) cij.err("content: %r" % content) return '' return find[0]
def regex_find(pattern, content): """Find the given 'pattern' in 'content'""" find = re.findall(pattern, content) if not find: cij.err("pattern <%r> is invalid, no matches!" % pattern) cij.err("content: %r" % content) return '' if len(find) >= 2: cij.err("pattern <%r> is too simple, matched more than 2!" % pattern) cij.err("content: %r" % content) return '' return find[0]
[ "Find", "the", "given", "pattern", "in", "content" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/util.py#L17-L31
[ "def", "regex_find", "(", "pattern", ",", "content", ")", ":", "find", "=", "re", ".", "findall", "(", "pattern", ",", "content", ")", "if", "not", "find", ":", "cij", ".", "err", "(", "\"pattern <%r> is invalid, no matches!\"", "%", "pattern", ")", "cij", ".", "err", "(", "\"content: %r\"", "%", "content", ")", "return", "''", "if", "len", "(", "find", ")", ">=", "2", ":", "cij", ".", "err", "(", "\"pattern <%r> is too simple, matched more than 2!\"", "%", "pattern", ")", "cij", ".", "err", "(", "\"content: %r\"", "%", "content", ")", "return", "''", "return", "find", "[", "0", "]" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
execute
Execute the given 'cmd' @returns (rcode, stdout, stderr)
modules/cij/util.py
def execute(cmd=None, shell=True, echo=True): """ Execute the given 'cmd' @returns (rcode, stdout, stderr) """ if echo: cij.emph("cij.util.execute: shell: %r, cmd: %r" % (shell, cmd)) rcode = 1 stdout, stderr = ("", "") if cmd: if shell: cmd = " ".join(cmd) proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell, close_fds=True) stdout, stderr = proc.communicate() rcode = proc.returncode if rcode and echo: cij.warn("cij.util.execute: stdout: %s" % stdout) cij.err("cij.util.execute: stderr: %s" % stderr) cij.err("cij.util.execute: rcode: %s" % rcode) return rcode, stdout, stderr
def execute(cmd=None, shell=True, echo=True): """ Execute the given 'cmd' @returns (rcode, stdout, stderr) """ if echo: cij.emph("cij.util.execute: shell: %r, cmd: %r" % (shell, cmd)) rcode = 1 stdout, stderr = ("", "") if cmd: if shell: cmd = " ".join(cmd) proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell, close_fds=True) stdout, stderr = proc.communicate() rcode = proc.returncode if rcode and echo: cij.warn("cij.util.execute: stdout: %s" % stdout) cij.err("cij.util.execute: stderr: %s" % stderr) cij.err("cij.util.execute: rcode: %s" % rcode) return rcode, stdout, stderr
[ "Execute", "the", "given", "cmd" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/util.py#L34-L59
[ "def", "execute", "(", "cmd", "=", "None", ",", "shell", "=", "True", ",", "echo", "=", "True", ")", ":", "if", "echo", ":", "cij", ".", "emph", "(", "\"cij.util.execute: shell: %r, cmd: %r\"", "%", "(", "shell", ",", "cmd", ")", ")", "rcode", "=", "1", "stdout", ",", "stderr", "=", "(", "\"\"", ",", "\"\"", ")", "if", "cmd", ":", "if", "shell", ":", "cmd", "=", "\" \"", ".", "join", "(", "cmd", ")", "proc", "=", "Popen", "(", "cmd", ",", "stdout", "=", "PIPE", ",", "stderr", "=", "PIPE", ",", "shell", "=", "shell", ",", "close_fds", "=", "True", ")", "stdout", ",", "stderr", "=", "proc", ".", "communicate", "(", ")", "rcode", "=", "proc", ".", "returncode", "if", "rcode", "and", "echo", ":", "cij", ".", "warn", "(", "\"cij.util.execute: stdout: %s\"", "%", "stdout", ")", "cij", ".", "err", "(", "\"cij.util.execute: stderr: %s\"", "%", "stderr", ")", "cij", ".", "err", "(", "\"cij.util.execute: rcode: %s\"", "%", "rcode", ")", "return", "rcode", ",", "stdout", ",", "stderr" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
env
Verify BOARD variables and construct exported variables
modules/cij/board.py
def env(): """Verify BOARD variables and construct exported variables""" if cij.ssh.env(): cij.err("board.env: invalid SSH environment") return 1 board = cij.env_to_dict(PREFIX, REQUIRED) # Verify REQUIRED variables if board is None: cij.err("board.env: invalid BOARD environment") return 1 board["CLASS"] = "_".join([board[r] for r in REQUIRED[:-1]]) board["IDENT"] = "-".join([board["CLASS"], board["ALIAS"]]) cij.env_export(PREFIX, EXPORTED, board) # Export EXPORTED variables return 0
def env(): """Verify BOARD variables and construct exported variables""" if cij.ssh.env(): cij.err("board.env: invalid SSH environment") return 1 board = cij.env_to_dict(PREFIX, REQUIRED) # Verify REQUIRED variables if board is None: cij.err("board.env: invalid BOARD environment") return 1 board["CLASS"] = "_".join([board[r] for r in REQUIRED[:-1]]) board["IDENT"] = "-".join([board["CLASS"], board["ALIAS"]]) cij.env_export(PREFIX, EXPORTED, board) # Export EXPORTED variables return 0
[ "Verify", "BOARD", "variables", "and", "construct", "exported", "variables" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/board.py#L12-L29
[ "def", "env", "(", ")", ":", "if", "cij", ".", "ssh", ".", "env", "(", ")", ":", "cij", ".", "err", "(", "\"board.env: invalid SSH environment\"", ")", "return", "1", "board", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "REQUIRED", ")", "# Verify REQUIRED variables", "if", "board", "is", "None", ":", "cij", ".", "err", "(", "\"board.env: invalid BOARD environment\"", ")", "return", "1", "board", "[", "\"CLASS\"", "]", "=", "\"_\"", ".", "join", "(", "[", "board", "[", "r", "]", "for", "r", "in", "REQUIRED", "[", ":", "-", "1", "]", "]", ")", "board", "[", "\"IDENT\"", "]", "=", "\"-\"", ".", "join", "(", "[", "board", "[", "\"CLASS\"", "]", ",", "board", "[", "\"ALIAS\"", "]", "]", ")", "cij", ".", "env_export", "(", "PREFIX", ",", "EXPORTED", ",", "board", ")", "# Export EXPORTED variables", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
cat_file
Cat file and return content
deprecated/modules/cij/nvme.py
def cat_file(path): """Cat file and return content""" cmd = ["cat", path] status, stdout, _ = cij.ssh.command(cmd, shell=True, echo=True) if status: raise RuntimeError("cij.nvme.env: cat %s failed" % path) return stdout.strip()
def cat_file(path): """Cat file and return content""" cmd = ["cat", path] status, stdout, _ = cij.ssh.command(cmd, shell=True, echo=True) if status: raise RuntimeError("cij.nvme.env: cat %s failed" % path) return stdout.strip()
[ "Cat", "file", "and", "return", "content" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/nvme.py#L30-L37
[ "def", "cat_file", "(", "path", ")", ":", "cmd", "=", "[", "\"cat\"", ",", "path", "]", "status", ",", "stdout", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ",", "echo", "=", "True", ")", "if", "status", ":", "raise", "RuntimeError", "(", "\"cij.nvme.env: cat %s failed\"", "%", "path", ")", "return", "stdout", ".", "strip", "(", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
env
Verify NVME variables and construct exported variables
deprecated/modules/cij/nvme.py
def env(): """Verify NVME variables and construct exported variables""" if cij.ssh.env(): cij.err("cij.nvme.env: invalid SSH environment") return 1 nvme = cij.env_to_dict(PREFIX, REQUIRED) nvme["DEV_PATH"] = os.path.join("/dev", nvme["DEV_NAME"]) # get version, chunks, luns and chs try: sysfs = os.path.join("/sys/class/block", nvme["DEV_NAME"], "lightnvm") nvme["LNVM_VERSION"] = cat_file(os.path.join(sysfs, "version")) if nvme["LNVM_VERSION"] == "2.0": luns = "punits" chs = "groups" elif nvme["LNVM_VERSION"] == "1.2": luns = "num_luns" chs = "num_channels" else: raise RuntimeError("cij.nvme.env: invalid lnvm version: %s" % nvme["LNVM_VERSION"]) nvme["LNVM_NUM_CHUNKS"] = cat_file(os.path.join(sysfs, "chunks")) nvme["LNVM_NUM_LUNS"] = cat_file(os.path.join(sysfs, luns)) nvme["LNVM_NUM_CHS"] = cat_file(os.path.join(sysfs, chs)) nvme["LNVM_TOTAL_LUNS"] = str(int(nvme["LNVM_NUM_LUNS"]) * int(nvme["LNVM_NUM_CHS"])) nvme["LNVM_TOTAL_CHUNKS"] = str(int(nvme["LNVM_TOTAL_LUNS"]) * int(nvme["LNVM_NUM_CHUNKS"])) # get spec version by identify namespace data struct if nvme["LNVM_VERSION"] == "2.0": cmd = ["nvme", "id-ctrl", nvme["DEV_PATH"], "--raw-binary"] status, stdout, _ = cij.ssh.command(cmd, shell=True) if status: raise RuntimeError("cij.nvme.env: nvme id-ctrl fail") buff = cij.bin.Buffer(types=IdentifyCDS, length=1) buff.memcopy(stdout) if buff[0].VS[1023] == 0x5a: nvme["SPEC_VERSION"] = "Denali" else: nvme["SPEC_VERSION"] = "Spec20" else: nvme["SPEC_VERSION"] = "Spec12" # get chunk meta information nvme["LNVM_CHUNK_META_LENGTH"] = str(get_sizeof_descriptor_table(nvme["SPEC_VERSION"])) nvme["LNVM_CHUNK_META_SIZE"] = str(int(nvme["LNVM_CHUNK_META_LENGTH"]) * int(nvme["LNVM_TOTAL_CHUNKS"])) except StandardError: traceback.print_exc() return 1 cij.env_export(PREFIX, EXPORTED, nvme) return 0
def env(): """Verify NVME variables and construct exported variables""" if cij.ssh.env(): cij.err("cij.nvme.env: invalid SSH environment") return 1 nvme = cij.env_to_dict(PREFIX, REQUIRED) nvme["DEV_PATH"] = os.path.join("/dev", nvme["DEV_NAME"]) # get version, chunks, luns and chs try: sysfs = os.path.join("/sys/class/block", nvme["DEV_NAME"], "lightnvm") nvme["LNVM_VERSION"] = cat_file(os.path.join(sysfs, "version")) if nvme["LNVM_VERSION"] == "2.0": luns = "punits" chs = "groups" elif nvme["LNVM_VERSION"] == "1.2": luns = "num_luns" chs = "num_channels" else: raise RuntimeError("cij.nvme.env: invalid lnvm version: %s" % nvme["LNVM_VERSION"]) nvme["LNVM_NUM_CHUNKS"] = cat_file(os.path.join(sysfs, "chunks")) nvme["LNVM_NUM_LUNS"] = cat_file(os.path.join(sysfs, luns)) nvme["LNVM_NUM_CHS"] = cat_file(os.path.join(sysfs, chs)) nvme["LNVM_TOTAL_LUNS"] = str(int(nvme["LNVM_NUM_LUNS"]) * int(nvme["LNVM_NUM_CHS"])) nvme["LNVM_TOTAL_CHUNKS"] = str(int(nvme["LNVM_TOTAL_LUNS"]) * int(nvme["LNVM_NUM_CHUNKS"])) # get spec version by identify namespace data struct if nvme["LNVM_VERSION"] == "2.0": cmd = ["nvme", "id-ctrl", nvme["DEV_PATH"], "--raw-binary"] status, stdout, _ = cij.ssh.command(cmd, shell=True) if status: raise RuntimeError("cij.nvme.env: nvme id-ctrl fail") buff = cij.bin.Buffer(types=IdentifyCDS, length=1) buff.memcopy(stdout) if buff[0].VS[1023] == 0x5a: nvme["SPEC_VERSION"] = "Denali" else: nvme["SPEC_VERSION"] = "Spec20" else: nvme["SPEC_VERSION"] = "Spec12" # get chunk meta information nvme["LNVM_CHUNK_META_LENGTH"] = str(get_sizeof_descriptor_table(nvme["SPEC_VERSION"])) nvme["LNVM_CHUNK_META_SIZE"] = str(int(nvme["LNVM_CHUNK_META_LENGTH"]) * int(nvme["LNVM_TOTAL_CHUNKS"])) except StandardError: traceback.print_exc() return 1 cij.env_export(PREFIX, EXPORTED, nvme) return 0
[ "Verify", "NVME", "variables", "and", "construct", "exported", "variables" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/nvme.py#L40-L100
[ "def", "env", "(", ")", ":", "if", "cij", ".", "ssh", ".", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.nvme.env: invalid SSH environment\"", ")", "return", "1", "nvme", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "REQUIRED", ")", "nvme", "[", "\"DEV_PATH\"", "]", "=", "os", ".", "path", ".", "join", "(", "\"/dev\"", ",", "nvme", "[", "\"DEV_NAME\"", "]", ")", "# get version, chunks, luns and chs", "try", ":", "sysfs", "=", "os", ".", "path", ".", "join", "(", "\"/sys/class/block\"", ",", "nvme", "[", "\"DEV_NAME\"", "]", ",", "\"lightnvm\"", ")", "nvme", "[", "\"LNVM_VERSION\"", "]", "=", "cat_file", "(", "os", ".", "path", ".", "join", "(", "sysfs", ",", "\"version\"", ")", ")", "if", "nvme", "[", "\"LNVM_VERSION\"", "]", "==", "\"2.0\"", ":", "luns", "=", "\"punits\"", "chs", "=", "\"groups\"", "elif", "nvme", "[", "\"LNVM_VERSION\"", "]", "==", "\"1.2\"", ":", "luns", "=", "\"num_luns\"", "chs", "=", "\"num_channels\"", "else", ":", "raise", "RuntimeError", "(", "\"cij.nvme.env: invalid lnvm version: %s\"", "%", "nvme", "[", "\"LNVM_VERSION\"", "]", ")", "nvme", "[", "\"LNVM_NUM_CHUNKS\"", "]", "=", "cat_file", "(", "os", ".", "path", ".", "join", "(", "sysfs", ",", "\"chunks\"", ")", ")", "nvme", "[", "\"LNVM_NUM_LUNS\"", "]", "=", "cat_file", "(", "os", ".", "path", ".", "join", "(", "sysfs", ",", "luns", ")", ")", "nvme", "[", "\"LNVM_NUM_CHS\"", "]", "=", "cat_file", "(", "os", ".", "path", ".", "join", "(", "sysfs", ",", "chs", ")", ")", "nvme", "[", "\"LNVM_TOTAL_LUNS\"", "]", "=", "str", "(", "int", "(", "nvme", "[", "\"LNVM_NUM_LUNS\"", "]", ")", "*", "int", "(", "nvme", "[", "\"LNVM_NUM_CHS\"", "]", ")", ")", "nvme", "[", "\"LNVM_TOTAL_CHUNKS\"", "]", "=", "str", "(", "int", "(", "nvme", "[", "\"LNVM_TOTAL_LUNS\"", "]", ")", "*", "int", "(", "nvme", "[", "\"LNVM_NUM_CHUNKS\"", "]", ")", ")", "# get spec version by identify namespace data struct", "if", "nvme", "[", "\"LNVM_VERSION\"", "]", "==", "\"2.0\"", ":", "cmd", "=", "[", "\"nvme\"", ",", "\"id-ctrl\"", ",", "nvme", "[", "\"DEV_PATH\"", "]", ",", "\"--raw-binary\"", "]", "status", ",", "stdout", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "if", "status", ":", "raise", "RuntimeError", "(", "\"cij.nvme.env: nvme id-ctrl fail\"", ")", "buff", "=", "cij", ".", "bin", ".", "Buffer", "(", "types", "=", "IdentifyCDS", ",", "length", "=", "1", ")", "buff", ".", "memcopy", "(", "stdout", ")", "if", "buff", "[", "0", "]", ".", "VS", "[", "1023", "]", "==", "0x5a", ":", "nvme", "[", "\"SPEC_VERSION\"", "]", "=", "\"Denali\"", "else", ":", "nvme", "[", "\"SPEC_VERSION\"", "]", "=", "\"Spec20\"", "else", ":", "nvme", "[", "\"SPEC_VERSION\"", "]", "=", "\"Spec12\"", "# get chunk meta information", "nvme", "[", "\"LNVM_CHUNK_META_LENGTH\"", "]", "=", "str", "(", "get_sizeof_descriptor_table", "(", "nvme", "[", "\"SPEC_VERSION\"", "]", ")", ")", "nvme", "[", "\"LNVM_CHUNK_META_SIZE\"", "]", "=", "str", "(", "int", "(", "nvme", "[", "\"LNVM_CHUNK_META_LENGTH\"", "]", ")", "*", "int", "(", "nvme", "[", "\"LNVM_TOTAL_CHUNKS\"", "]", ")", ")", "except", "StandardError", ":", "traceback", ".", "print_exc", "(", ")", "return", "1", "cij", ".", "env_export", "(", "PREFIX", ",", "EXPORTED", ",", "nvme", ")", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
fmt
Do format for NVMe device
deprecated/modules/cij/nvme.py
def fmt(lbaf=3): """Do format for NVMe device""" if env(): cij.err("cij.nvme.exists: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) cmd = ["nvme", "format", nvme["DEV_PATH"], "-l", str(lbaf)] rcode, _, _ = cij.ssh.command(cmd, shell=True) return rcode
def fmt(lbaf=3): """Do format for NVMe device""" if env(): cij.err("cij.nvme.exists: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) cmd = ["nvme", "format", nvme["DEV_PATH"], "-l", str(lbaf)] rcode, _, _ = cij.ssh.command(cmd, shell=True) return rcode
[ "Do", "format", "for", "NVMe", "device" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/nvme.py#L103-L115
[ "def", "fmt", "(", "lbaf", "=", "3", ")", ":", "if", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.nvme.exists: Invalid NVMe ENV.\"", ")", "return", "1", "nvme", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "EXPORTED", "+", "REQUIRED", ")", "cmd", "=", "[", "\"nvme\"", ",", "\"format\"", ",", "nvme", "[", "\"DEV_PATH\"", "]", ",", "\"-l\"", ",", "str", "(", "lbaf", ")", "]", "rcode", ",", "_", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "return", "rcode" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
get_meta
Get chunk meta of NVMe device
deprecated/modules/cij/nvme.py
def get_meta(offset, length, output): """Get chunk meta of NVMe device""" if env(): cij.err("cij.nvme.meta: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) max_size = 0x40000 with open(output, "wb") as fout: for off in range(offset, length, max_size): size = min(length - off, max_size) cmd = ["nvme get-log", nvme["DEV_PATH"], "-i 0xca", "-o 0x%x" % off, "-l 0x%x" % size, "-b"] status, stdout, _ = cij.ssh.command(cmd, shell=True) if status: cij.err("cij.nvme.meta: Error get chunk meta") return 1 fout.write(stdout) return 0
def get_meta(offset, length, output): """Get chunk meta of NVMe device""" if env(): cij.err("cij.nvme.meta: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) max_size = 0x40000 with open(output, "wb") as fout: for off in range(offset, length, max_size): size = min(length - off, max_size) cmd = ["nvme get-log", nvme["DEV_PATH"], "-i 0xca", "-o 0x%x" % off, "-l 0x%x" % size, "-b"] status, stdout, _ = cij.ssh.command(cmd, shell=True) if status: cij.err("cij.nvme.meta: Error get chunk meta") return 1 fout.write(stdout) return 0
[ "Get", "chunk", "meta", "of", "NVMe", "device" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/nvme.py#L135-L161
[ "def", "get_meta", "(", "offset", ",", "length", ",", "output", ")", ":", "if", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.nvme.meta: Invalid NVMe ENV.\"", ")", "return", "1", "nvme", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "EXPORTED", "+", "REQUIRED", ")", "max_size", "=", "0x40000", "with", "open", "(", "output", ",", "\"wb\"", ")", "as", "fout", ":", "for", "off", "in", "range", "(", "offset", ",", "length", ",", "max_size", ")", ":", "size", "=", "min", "(", "length", "-", "off", ",", "max_size", ")", "cmd", "=", "[", "\"nvme get-log\"", ",", "nvme", "[", "\"DEV_PATH\"", "]", ",", "\"-i 0xca\"", ",", "\"-o 0x%x\"", "%", "off", ",", "\"-l 0x%x\"", "%", "size", ",", "\"-b\"", "]", "status", ",", "stdout", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "if", "status", ":", "cij", ".", "err", "(", "\"cij.nvme.meta: Error get chunk meta\"", ")", "return", "1", "fout", ".", "write", "(", "stdout", ")", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
comp_meta
Compare chunk meta, mode=[pfail, power, reboot]
deprecated/modules/cij/nvme.py
def comp_meta(file_bef, file_aft, mode="pfail"): """Compare chunk meta, mode=[pfail, power, reboot]""" if env(): cij.err("cij.nvme.comp_meta: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) num_chk = int(nvme["LNVM_TOTAL_CHUNKS"]) meta_bef = cij.bin.Buffer(types=get_descriptor_table(nvme['SPEC_VERSION']), length=num_chk) meta_aft = cij.bin.Buffer(types=get_descriptor_table(nvme['SPEC_VERSION']), length=num_chk) meta_bef.read(file_bef) meta_aft.read(file_aft) for chk in range(num_chk): ignore = ["WL", "RSV0"] # PFAIL: BEFORE IS OPEN CHUNK, WRITE POINTER IS NOT SURE, IGNORE if mode == "pfail" and meta_bef[chk].CS == 4: ignore.append("WP") # COMPARE CHUNK META if meta_bef.compare(meta_aft, chk, ignore=ignore): cij.warn("META_BUFF_BEF[%s]:" % chk) meta_bef.dump(chk) cij.warn("META_BUFF_AFT[%s]:" % chk) meta_aft.dump(chk) cij.err("Error compare, CHUNK: %s" % chk) return 1 return 0
def comp_meta(file_bef, file_aft, mode="pfail"): """Compare chunk meta, mode=[pfail, power, reboot]""" if env(): cij.err("cij.nvme.comp_meta: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) num_chk = int(nvme["LNVM_TOTAL_CHUNKS"]) meta_bef = cij.bin.Buffer(types=get_descriptor_table(nvme['SPEC_VERSION']), length=num_chk) meta_aft = cij.bin.Buffer(types=get_descriptor_table(nvme['SPEC_VERSION']), length=num_chk) meta_bef.read(file_bef) meta_aft.read(file_aft) for chk in range(num_chk): ignore = ["WL", "RSV0"] # PFAIL: BEFORE IS OPEN CHUNK, WRITE POINTER IS NOT SURE, IGNORE if mode == "pfail" and meta_bef[chk].CS == 4: ignore.append("WP") # COMPARE CHUNK META if meta_bef.compare(meta_aft, chk, ignore=ignore): cij.warn("META_BUFF_BEF[%s]:" % chk) meta_bef.dump(chk) cij.warn("META_BUFF_AFT[%s]:" % chk) meta_aft.dump(chk) cij.err("Error compare, CHUNK: %s" % chk) return 1 return 0
[ "Compare", "chunk", "meta", "mode", "=", "[", "pfail", "power", "reboot", "]" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/nvme.py#L164-L194
[ "def", "comp_meta", "(", "file_bef", ",", "file_aft", ",", "mode", "=", "\"pfail\"", ")", ":", "if", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.nvme.comp_meta: Invalid NVMe ENV.\"", ")", "return", "1", "nvme", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "EXPORTED", "+", "REQUIRED", ")", "num_chk", "=", "int", "(", "nvme", "[", "\"LNVM_TOTAL_CHUNKS\"", "]", ")", "meta_bef", "=", "cij", ".", "bin", ".", "Buffer", "(", "types", "=", "get_descriptor_table", "(", "nvme", "[", "'SPEC_VERSION'", "]", ")", ",", "length", "=", "num_chk", ")", "meta_aft", "=", "cij", ".", "bin", ".", "Buffer", "(", "types", "=", "get_descriptor_table", "(", "nvme", "[", "'SPEC_VERSION'", "]", ")", ",", "length", "=", "num_chk", ")", "meta_bef", ".", "read", "(", "file_bef", ")", "meta_aft", ".", "read", "(", "file_aft", ")", "for", "chk", "in", "range", "(", "num_chk", ")", ":", "ignore", "=", "[", "\"WL\"", ",", "\"RSV0\"", "]", "# PFAIL: BEFORE IS OPEN CHUNK, WRITE POINTER IS NOT SURE, IGNORE", "if", "mode", "==", "\"pfail\"", "and", "meta_bef", "[", "chk", "]", ".", "CS", "==", "4", ":", "ignore", ".", "append", "(", "\"WP\"", ")", "# COMPARE CHUNK META", "if", "meta_bef", ".", "compare", "(", "meta_aft", ",", "chk", ",", "ignore", "=", "ignore", ")", ":", "cij", ".", "warn", "(", "\"META_BUFF_BEF[%s]:\"", "%", "chk", ")", "meta_bef", ".", "dump", "(", "chk", ")", "cij", ".", "warn", "(", "\"META_BUFF_AFT[%s]:\"", "%", "chk", ")", "meta_aft", ".", "dump", "(", "chk", ")", "cij", ".", "err", "(", "\"Error compare, CHUNK: %s\"", "%", "chk", ")", "return", "1", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
get_sizeof_descriptor_table
Get sizeof DescriptorTable
deprecated/modules/cij/struct/chunk_info.py
def get_sizeof_descriptor_table(version="Denali"): """ Get sizeof DescriptorTable """ if version == "Denali": return sizeof(DescriptorTableDenali) elif version == "Spec20": return sizeof(DescriptorTableSpec20) elif version == "Spec12": return 0 else: raise RuntimeError("Error version!")
def get_sizeof_descriptor_table(version="Denali"): """ Get sizeof DescriptorTable """ if version == "Denali": return sizeof(DescriptorTableDenali) elif version == "Spec20": return sizeof(DescriptorTableSpec20) elif version == "Spec12": return 0 else: raise RuntimeError("Error version!")
[ "Get", "sizeof", "DescriptorTable" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/struct/chunk_info.py#L53-L64
[ "def", "get_sizeof_descriptor_table", "(", "version", "=", "\"Denali\"", ")", ":", "if", "version", "==", "\"Denali\"", ":", "return", "sizeof", "(", "DescriptorTableDenali", ")", "elif", "version", "==", "\"Spec20\"", ":", "return", "sizeof", "(", "DescriptorTableSpec20", ")", "elif", "version", "==", "\"Spec12\"", ":", "return", "0", "else", ":", "raise", "RuntimeError", "(", "\"Error version!\"", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
env
Verify LNVM variables and construct exported variables
modules/cij/lnvm.py
def env(): """Verify LNVM variables and construct exported variables""" if cij.ssh.env(): cij.err("cij.lnvm.env: invalid SSH environment") return 1 lnvm = cij.env_to_dict(PREFIX, REQUIRED) nvme = cij.env_to_dict("NVME", ["DEV_NAME"]) if "BGN" not in lnvm.keys(): cij.err("cij.lnvm.env: invalid LNVM_BGN") return 1 if "END" not in lnvm.keys(): cij.err("cij.lnvm.env: invalid LNVM_END") return 1 if "DEV_TYPE" not in lnvm.keys(): cij.err("cij.lnvm.env: invalid LNVM_DEV_TYPE") return 1 lnvm["DEV_NAME"] = "%sb%03de%03d" % (nvme["DEV_NAME"], int(lnvm["BGN"]), int(lnvm["END"])) lnvm["DEV_PATH"] = "/dev/%s" % lnvm["DEV_NAME"] cij.env_export(PREFIX, EXPORTED, lnvm) return 0
def env(): """Verify LNVM variables and construct exported variables""" if cij.ssh.env(): cij.err("cij.lnvm.env: invalid SSH environment") return 1 lnvm = cij.env_to_dict(PREFIX, REQUIRED) nvme = cij.env_to_dict("NVME", ["DEV_NAME"]) if "BGN" not in lnvm.keys(): cij.err("cij.lnvm.env: invalid LNVM_BGN") return 1 if "END" not in lnvm.keys(): cij.err("cij.lnvm.env: invalid LNVM_END") return 1 if "DEV_TYPE" not in lnvm.keys(): cij.err("cij.lnvm.env: invalid LNVM_DEV_TYPE") return 1 lnvm["DEV_NAME"] = "%sb%03de%03d" % (nvme["DEV_NAME"], int(lnvm["BGN"]), int(lnvm["END"])) lnvm["DEV_PATH"] = "/dev/%s" % lnvm["DEV_NAME"] cij.env_export(PREFIX, EXPORTED, lnvm) return 0
[ "Verify", "LNVM", "variables", "and", "construct", "exported", "variables" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/lnvm.py#L13-L38
[ "def", "env", "(", ")", ":", "if", "cij", ".", "ssh", ".", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.lnvm.env: invalid SSH environment\"", ")", "return", "1", "lnvm", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "REQUIRED", ")", "nvme", "=", "cij", ".", "env_to_dict", "(", "\"NVME\"", ",", "[", "\"DEV_NAME\"", "]", ")", "if", "\"BGN\"", "not", "in", "lnvm", ".", "keys", "(", ")", ":", "cij", ".", "err", "(", "\"cij.lnvm.env: invalid LNVM_BGN\"", ")", "return", "1", "if", "\"END\"", "not", "in", "lnvm", ".", "keys", "(", ")", ":", "cij", ".", "err", "(", "\"cij.lnvm.env: invalid LNVM_END\"", ")", "return", "1", "if", "\"DEV_TYPE\"", "not", "in", "lnvm", ".", "keys", "(", ")", ":", "cij", ".", "err", "(", "\"cij.lnvm.env: invalid LNVM_DEV_TYPE\"", ")", "return", "1", "lnvm", "[", "\"DEV_NAME\"", "]", "=", "\"%sb%03de%03d\"", "%", "(", "nvme", "[", "\"DEV_NAME\"", "]", ",", "int", "(", "lnvm", "[", "\"BGN\"", "]", ")", ",", "int", "(", "lnvm", "[", "\"END\"", "]", ")", ")", "lnvm", "[", "\"DEV_PATH\"", "]", "=", "\"/dev/%s\"", "%", "lnvm", "[", "\"DEV_NAME\"", "]", "cij", ".", "env_export", "(", "PREFIX", ",", "EXPORTED", ",", "lnvm", ")", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
create
Create LNVM device
modules/cij/lnvm.py
def create(): """Create LNVM device""" if env(): cij.err("cij.lnvm.create: Invalid LNVM ENV") return 1 nvme = cij.env_to_dict("NVME", ["DEV_NAME"]) lnvm = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) cij.emph("lnvm.create: LNVM_DEV_NAME: %s" % lnvm["DEV_NAME"]) cmd = ["nvme lnvm create -d %s -n %s -t %s -b %s -e %s -f" % ( nvme["DEV_NAME"], lnvm["DEV_NAME"], lnvm["DEV_TYPE"], lnvm["BGN"], lnvm["END"])] rcode, _, _ = cij.ssh.command(cmd, shell=True) if rcode: cij.err("cij.lnvm.create: FAILED") return 1 return 0
def create(): """Create LNVM device""" if env(): cij.err("cij.lnvm.create: Invalid LNVM ENV") return 1 nvme = cij.env_to_dict("NVME", ["DEV_NAME"]) lnvm = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) cij.emph("lnvm.create: LNVM_DEV_NAME: %s" % lnvm["DEV_NAME"]) cmd = ["nvme lnvm create -d %s -n %s -t %s -b %s -e %s -f" % ( nvme["DEV_NAME"], lnvm["DEV_NAME"], lnvm["DEV_TYPE"], lnvm["BGN"], lnvm["END"])] rcode, _, _ = cij.ssh.command(cmd, shell=True) if rcode: cij.err("cij.lnvm.create: FAILED") return 1 return 0
[ "Create", "LNVM", "device" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/lnvm.py#L41-L59
[ "def", "create", "(", ")", ":", "if", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.lnvm.create: Invalid LNVM ENV\"", ")", "return", "1", "nvme", "=", "cij", ".", "env_to_dict", "(", "\"NVME\"", ",", "[", "\"DEV_NAME\"", "]", ")", "lnvm", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "EXPORTED", "+", "REQUIRED", ")", "cij", ".", "emph", "(", "\"lnvm.create: LNVM_DEV_NAME: %s\"", "%", "lnvm", "[", "\"DEV_NAME\"", "]", ")", "cmd", "=", "[", "\"nvme lnvm create -d %s -n %s -t %s -b %s -e %s -f\"", "%", "(", "nvme", "[", "\"DEV_NAME\"", "]", ",", "lnvm", "[", "\"DEV_NAME\"", "]", ",", "lnvm", "[", "\"DEV_TYPE\"", "]", ",", "lnvm", "[", "\"BGN\"", "]", ",", "lnvm", "[", "\"END\"", "]", ")", "]", "rcode", ",", "_", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "if", "rcode", ":", "cij", ".", "err", "(", "\"cij.lnvm.create: FAILED\"", ")", "return", "1", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
dump
Dump UnionType/StructType to STDOUT
modules/cij/bin.py
def dump(buf, indent=0, skip=""): """Dump UnionType/StructType to STDOUT""" if not isinstance(type(buf), (type(Union), type(Structure))): raise RuntimeError("Error type(%s)" % type(buf)) for field in getattr(buf, '_fields_'): name, types = field[0], field[1] if name in skip: return value = getattr(buf, name) if isinstance(types, (type(Union), type(Structure))): cij.info("%s%s:" % (" " * indent, name)) dump(value, indent+2, skip) elif isinstance(types, type(Array)): for i, item in enumerate(value): name_index = "%s[%s]" % (name, i) if isinstance(types, (type(Union), type(Structure))): cij.info("%s%s:" % (" " * indent, name_index)) dump(item, indent + 2, skip) else: cij.info("%s%-12s: 0x%x" % (" " * indent, name_index, item)) else: cij.info("%s%-12s: 0x%x" % (" " * indent, name, value))
def dump(buf, indent=0, skip=""): """Dump UnionType/StructType to STDOUT""" if not isinstance(type(buf), (type(Union), type(Structure))): raise RuntimeError("Error type(%s)" % type(buf)) for field in getattr(buf, '_fields_'): name, types = field[0], field[1] if name in skip: return value = getattr(buf, name) if isinstance(types, (type(Union), type(Structure))): cij.info("%s%s:" % (" " * indent, name)) dump(value, indent+2, skip) elif isinstance(types, type(Array)): for i, item in enumerate(value): name_index = "%s[%s]" % (name, i) if isinstance(types, (type(Union), type(Structure))): cij.info("%s%s:" % (" " * indent, name_index)) dump(item, indent + 2, skip) else: cij.info("%s%-12s: 0x%x" % (" " * indent, name_index, item)) else: cij.info("%s%-12s: 0x%x" % (" " * indent, name, value))
[ "Dump", "UnionType", "/", "StructType", "to", "STDOUT" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L19-L43
[ "def", "dump", "(", "buf", ",", "indent", "=", "0", ",", "skip", "=", "\"\"", ")", ":", "if", "not", "isinstance", "(", "type", "(", "buf", ")", ",", "(", "type", "(", "Union", ")", ",", "type", "(", "Structure", ")", ")", ")", ":", "raise", "RuntimeError", "(", "\"Error type(%s)\"", "%", "type", "(", "buf", ")", ")", "for", "field", "in", "getattr", "(", "buf", ",", "'_fields_'", ")", ":", "name", ",", "types", "=", "field", "[", "0", "]", ",", "field", "[", "1", "]", "if", "name", "in", "skip", ":", "return", "value", "=", "getattr", "(", "buf", ",", "name", ")", "if", "isinstance", "(", "types", ",", "(", "type", "(", "Union", ")", ",", "type", "(", "Structure", ")", ")", ")", ":", "cij", ".", "info", "(", "\"%s%s:\"", "%", "(", "\" \"", "*", "indent", ",", "name", ")", ")", "dump", "(", "value", ",", "indent", "+", "2", ",", "skip", ")", "elif", "isinstance", "(", "types", ",", "type", "(", "Array", ")", ")", ":", "for", "i", ",", "item", "in", "enumerate", "(", "value", ")", ":", "name_index", "=", "\"%s[%s]\"", "%", "(", "name", ",", "i", ")", "if", "isinstance", "(", "types", ",", "(", "type", "(", "Union", ")", ",", "type", "(", "Structure", ")", ")", ")", ":", "cij", ".", "info", "(", "\"%s%s:\"", "%", "(", "\" \"", "*", "indent", ",", "name_index", ")", ")", "dump", "(", "item", ",", "indent", "+", "2", ",", "skip", ")", "else", ":", "cij", ".", "info", "(", "\"%s%-12s: 0x%x\"", "%", "(", "\" \"", "*", "indent", ",", "name_index", ",", "item", ")", ")", "else", ":", "cij", ".", "info", "(", "\"%s%-12s: 0x%x\"", "%", "(", "\" \"", "*", "indent", ",", "name", ",", "value", ")", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
compare
Compare of two Buffer item
modules/cij/bin.py
def compare(buf_a, buf_b, ignore): """Compare of two Buffer item""" for field in getattr(buf_a, '_fields_'): name, types = field[0], field[1] if name in ignore: continue val_a = getattr(buf_a, name) val_b = getattr(buf_b, name) if isinstance(types, (type(Union), type(Structure))): if compare(val_a, val_b, ignore): return 1 elif isinstance(types, type(Array)): for i, _ in enumerate(val_a): if isinstance(types, (type(Union), type(Structure))): if compare(val_a[i], val_b[i], ignore): return 1 else: if val_a[i] != val_b[i]: return 1 else: if val_a != val_b: return 1 return 0
def compare(buf_a, buf_b, ignore): """Compare of two Buffer item""" for field in getattr(buf_a, '_fields_'): name, types = field[0], field[1] if name in ignore: continue val_a = getattr(buf_a, name) val_b = getattr(buf_b, name) if isinstance(types, (type(Union), type(Structure))): if compare(val_a, val_b, ignore): return 1 elif isinstance(types, type(Array)): for i, _ in enumerate(val_a): if isinstance(types, (type(Union), type(Structure))): if compare(val_a[i], val_b[i], ignore): return 1 else: if val_a[i] != val_b[i]: return 1 else: if val_a != val_b: return 1 return 0
[ "Compare", "of", "two", "Buffer", "item" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L46-L72
[ "def", "compare", "(", "buf_a", ",", "buf_b", ",", "ignore", ")", ":", "for", "field", "in", "getattr", "(", "buf_a", ",", "'_fields_'", ")", ":", "name", ",", "types", "=", "field", "[", "0", "]", ",", "field", "[", "1", "]", "if", "name", "in", "ignore", ":", "continue", "val_a", "=", "getattr", "(", "buf_a", ",", "name", ")", "val_b", "=", "getattr", "(", "buf_b", ",", "name", ")", "if", "isinstance", "(", "types", ",", "(", "type", "(", "Union", ")", ",", "type", "(", "Structure", ")", ")", ")", ":", "if", "compare", "(", "val_a", ",", "val_b", ",", "ignore", ")", ":", "return", "1", "elif", "isinstance", "(", "types", ",", "type", "(", "Array", ")", ")", ":", "for", "i", ",", "_", "in", "enumerate", "(", "val_a", ")", ":", "if", "isinstance", "(", "types", ",", "(", "type", "(", "Union", ")", ",", "type", "(", "Structure", ")", ")", ")", ":", "if", "compare", "(", "val_a", "[", "i", "]", ",", "val_b", "[", "i", "]", ",", "ignore", ")", ":", "return", "1", "else", ":", "if", "val_a", "[", "i", "]", "!=", "val_b", "[", "i", "]", ":", "return", "1", "else", ":", "if", "val_a", "!=", "val_b", ":", "return", "1", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Buffer.memcopy
Copy stream to buffer
modules/cij/bin.py
def memcopy(self, stream, offset=0, length=float("inf")): """Copy stream to buffer""" data = [ord(i) for i in list(stream)] size = min(length, len(data), self.m_size) buff = cast(self.m_buf, POINTER(c_uint8)) for i in range(size): buff[offset + i] = data[i]
def memcopy(self, stream, offset=0, length=float("inf")): """Copy stream to buffer""" data = [ord(i) for i in list(stream)] size = min(length, len(data), self.m_size) buff = cast(self.m_buf, POINTER(c_uint8)) for i in range(size): buff[offset + i] = data[i]
[ "Copy", "stream", "to", "buffer" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L106-L112
[ "def", "memcopy", "(", "self", ",", "stream", ",", "offset", "=", "0", ",", "length", "=", "float", "(", "\"inf\"", ")", ")", ":", "data", "=", "[", "ord", "(", "i", ")", "for", "i", "in", "list", "(", "stream", ")", "]", "size", "=", "min", "(", "length", ",", "len", "(", "data", ")", ",", "self", ".", "m_size", ")", "buff", "=", "cast", "(", "self", ".", "m_buf", ",", "POINTER", "(", "c_uint8", ")", ")", "for", "i", "in", "range", "(", "size", ")", ":", "buff", "[", "offset", "+", "i", "]", "=", "data", "[", "i", "]" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Buffer.write
Write buffer to file
modules/cij/bin.py
def write(self, path): """Write buffer to file""" with open(path, "wb") as fout: fout.write(self.m_buf)
def write(self, path): """Write buffer to file""" with open(path, "wb") as fout: fout.write(self.m_buf)
[ "Write", "buffer", "to", "file" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L114-L118
[ "def", "write", "(", "self", ",", "path", ")", ":", "with", "open", "(", "path", ",", "\"wb\"", ")", "as", "fout", ":", "fout", ".", "write", "(", "self", ".", "m_buf", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Buffer.read
Read file to buffer
modules/cij/bin.py
def read(self, path): """Read file to buffer""" with open(path, "rb") as fout: memmove(self.m_buf, fout.read(self.m_size), self.m_size)
def read(self, path): """Read file to buffer""" with open(path, "rb") as fout: memmove(self.m_buf, fout.read(self.m_size), self.m_size)
[ "Read", "file", "to", "buffer" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L120-L124
[ "def", "read", "(", "self", ",", "path", ")", ":", "with", "open", "(", "path", ",", "\"rb\"", ")", "as", "fout", ":", "memmove", "(", "self", ".", "m_buf", ",", "fout", ".", "read", "(", "self", ".", "m_size", ")", ",", "self", ".", "m_size", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Buffer.dump
Dump item
modules/cij/bin.py
def dump(self, offset=0, length=1): """Dump item""" for i in range(offset, offset + length): if "ctypes" in str(self.m_types): cij.info("Buff[%s]: %s" % (i, self.m_buf[i])) else: cij.info("Buff[%s]:" % i) dump(self.m_buf[i], 2)
def dump(self, offset=0, length=1): """Dump item""" for i in range(offset, offset + length): if "ctypes" in str(self.m_types): cij.info("Buff[%s]: %s" % (i, self.m_buf[i])) else: cij.info("Buff[%s]:" % i) dump(self.m_buf[i], 2)
[ "Dump", "item" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L126-L134
[ "def", "dump", "(", "self", ",", "offset", "=", "0", ",", "length", "=", "1", ")", ":", "for", "i", "in", "range", "(", "offset", ",", "offset", "+", "length", ")", ":", "if", "\"ctypes\"", "in", "str", "(", "self", ".", "m_types", ")", ":", "cij", ".", "info", "(", "\"Buff[%s]: %s\"", "%", "(", "i", ",", "self", ".", "m_buf", "[", "i", "]", ")", ")", "else", ":", "cij", ".", "info", "(", "\"Buff[%s]:\"", "%", "i", ")", "dump", "(", "self", ".", "m_buf", "[", "i", "]", ",", "2", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Buffer.compare
Compare buffer
modules/cij/bin.py
def compare(self, buf, offset=0, length=1, ignore=""): """Compare buffer""" for i in range(offset, offset + length): if isinstance(self.m_types, (type(Union), type(Structure))): if compare(self.m_buf[i], buf[i], ignore=ignore): return 1 elif self.m_buf[i] != buf[i]: return 1 return 0
def compare(self, buf, offset=0, length=1, ignore=""): """Compare buffer""" for i in range(offset, offset + length): if isinstance(self.m_types, (type(Union), type(Structure))): if compare(self.m_buf[i], buf[i], ignore=ignore): return 1 elif self.m_buf[i] != buf[i]: return 1 return 0
[ "Compare", "buffer" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/bin.py#L136-L146
[ "def", "compare", "(", "self", ",", "buf", ",", "offset", "=", "0", ",", "length", "=", "1", ",", "ignore", "=", "\"\"", ")", ":", "for", "i", "in", "range", "(", "offset", ",", "offset", "+", "length", ")", ":", "if", "isinstance", "(", "self", ".", "m_types", ",", "(", "type", "(", "Union", ")", ",", "type", "(", "Structure", ")", ")", ")", ":", "if", "compare", "(", "self", ".", "m_buf", "[", "i", "]", ",", "buf", "[", "i", "]", ",", "ignore", "=", "ignore", ")", ":", "return", "1", "elif", "self", ".", "m_buf", "[", "i", "]", "!=", "buf", "[", "i", "]", ":", "return", "1", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Relay.power_on
230v power on
modules/cij/usb.py
def power_on(self, interval=200): """230v power on""" if self.__power_on_port is None: cij.err("cij.usb.relay: Invalid USB_RELAY_POWER_ON") return 1 return self.__press(self.__power_on_port, interval=interval)
def power_on(self, interval=200): """230v power on""" if self.__power_on_port is None: cij.err("cij.usb.relay: Invalid USB_RELAY_POWER_ON") return 1 return self.__press(self.__power_on_port, interval=interval)
[ "230v", "power", "on" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/usb.py#L99-L105
[ "def", "power_on", "(", "self", ",", "interval", "=", "200", ")", ":", "if", "self", ".", "__power_on_port", "is", "None", ":", "cij", ".", "err", "(", "\"cij.usb.relay: Invalid USB_RELAY_POWER_ON\"", ")", "return", "1", "return", "self", ".", "__press", "(", "self", ".", "__power_on_port", ",", "interval", "=", "interval", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Relay.power_off
230v power off
modules/cij/usb.py
def power_off(self, interval=200): """230v power off""" if self.__power_off_port is None: cij.err("cij.usb.relay: Invalid USB_RELAY_POWER_OFF") return 1 return self.__press(self.__power_off_port, interval=interval)
def power_off(self, interval=200): """230v power off""" if self.__power_off_port is None: cij.err("cij.usb.relay: Invalid USB_RELAY_POWER_OFF") return 1 return self.__press(self.__power_off_port, interval=interval)
[ "230v", "power", "off" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/usb.py#L107-L113
[ "def", "power_off", "(", "self", ",", "interval", "=", "200", ")", ":", "if", "self", ".", "__power_off_port", "is", "None", ":", "cij", ".", "err", "(", "\"cij.usb.relay: Invalid USB_RELAY_POWER_OFF\"", ")", "return", "1", "return", "self", ".", "__press", "(", "self", ".", "__power_off_port", ",", "interval", "=", "interval", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Relay.power_btn
TARGET power button
modules/cij/usb.py
def power_btn(self, interval=200): """TARGET power button""" if self.__power_btn_port is None: cij.err("cij.usb.relay: Invalid USB_RELAY_POWER_BTN") return 1 return self.__press(self.__power_btn_port, interval=interval)
def power_btn(self, interval=200): """TARGET power button""" if self.__power_btn_port is None: cij.err("cij.usb.relay: Invalid USB_RELAY_POWER_BTN") return 1 return self.__press(self.__power_btn_port, interval=interval)
[ "TARGET", "power", "button" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/usb.py#L115-L121
[ "def", "power_btn", "(", "self", ",", "interval", "=", "200", ")", ":", "if", "self", ".", "__power_btn_port", "is", "None", ":", "cij", ".", "err", "(", "\"cij.usb.relay: Invalid USB_RELAY_POWER_BTN\"", ")", "return", "1", "return", "self", ".", "__press", "(", "self", ".", "__power_btn_port", ",", "interval", "=", "interval", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.get_chunk_information
Get chunk information
deprecated/modules/cij/spdk.py
def get_chunk_information(self, chk, lun, chunk_name): """Get chunk information""" cmd = ["nvm_cmd rprt_lun", self.envs, "%d %d > %s" % (chk, lun, chunk_name)] status, _, _ = cij.ssh.command(cmd, shell=True) return status
def get_chunk_information(self, chk, lun, chunk_name): """Get chunk information""" cmd = ["nvm_cmd rprt_lun", self.envs, "%d %d > %s" % (chk, lun, chunk_name)] status, _, _ = cij.ssh.command(cmd, shell=True) return status
[ "Get", "chunk", "information" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L55-L60
[ "def", "get_chunk_information", "(", "self", ",", "chk", ",", "lun", ",", "chunk_name", ")", ":", "cmd", "=", "[", "\"nvm_cmd rprt_lun\"", ",", "self", ".", "envs", ",", "\"%d %d > %s\"", "%", "(", "chk", ",", "lun", ",", "chunk_name", ")", "]", "status", ",", "_", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "return", "status" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.is_bad_chunk
Check the chunk is offline or not
deprecated/modules/cij/spdk.py
def is_bad_chunk(self, chk, yml): """Check the chunk is offline or not""" cs = self.get_chunk_status(chk, yml) if cs >= 8: return True return False
def is_bad_chunk(self, chk, yml): """Check the chunk is offline or not""" cs = self.get_chunk_status(chk, yml) if cs >= 8: return True return False
[ "Check", "the", "chunk", "is", "offline", "or", "not" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L62-L67
[ "def", "is_bad_chunk", "(", "self", ",", "chk", ",", "yml", ")", ":", "cs", "=", "self", ".", "get_chunk_status", "(", "chk", ",", "yml", ")", "if", "cs", ">=", "8", ":", "return", "True", "return", "False" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.is_free_chunk
Check the chunk is free or not
deprecated/modules/cij/spdk.py
def is_free_chunk(self, chk): """Check the chunk is free or not""" cs = self.get_chunk_status(chk) if cs & 0x1 != 0: return True return False
def is_free_chunk(self, chk): """Check the chunk is free or not""" cs = self.get_chunk_status(chk) if cs & 0x1 != 0: return True return False
[ "Check", "the", "chunk", "is", "free", "or", "not" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L69-L74
[ "def", "is_free_chunk", "(", "self", ",", "chk", ")", ":", "cs", "=", "self", ".", "get_chunk_status", "(", "chk", ")", "if", "cs", "&", "0x1", "!=", "0", ":", "return", "True", "return", "False" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.is_closed_chunk
Check the chunk is free or not
deprecated/modules/cij/spdk.py
def is_closed_chunk(self, chk): """Check the chunk is free or not""" cs = self.get_chunk_status(chk) if cs & 0x2 != 0: return True return False
def is_closed_chunk(self, chk): """Check the chunk is free or not""" cs = self.get_chunk_status(chk) if cs & 0x2 != 0: return True return False
[ "Check", "the", "chunk", "is", "free", "or", "not" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L76-L81
[ "def", "is_closed_chunk", "(", "self", ",", "chk", ")", ":", "cs", "=", "self", ".", "get_chunk_status", "(", "chk", ")", "if", "cs", "&", "0x2", "!=", "0", ":", "return", "True", "return", "False" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.is_open_chunk
Check the chunk is free or not
deprecated/modules/cij/spdk.py
def is_open_chunk(self, chk): """Check the chunk is free or not""" cs = self.get_chunk_status(chk) if cs & 0x4 != 0: return True return False
def is_open_chunk(self, chk): """Check the chunk is free or not""" cs = self.get_chunk_status(chk) if cs & 0x4 != 0: return True return False
[ "Check", "the", "chunk", "is", "free", "or", "not" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L83-L88
[ "def", "is_open_chunk", "(", "self", ",", "chk", ")", ":", "cs", "=", "self", ".", "get_chunk_status", "(", "chk", ")", "if", "cs", "&", "0x4", "!=", "0", ":", "return", "True", "return", "False" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.vblk_erase
nvm_vblk erase
deprecated/modules/cij/spdk.py
def vblk_erase(self, address): """nvm_vblk erase""" cmd = ["nvm_vblk erase", self.envs, "0x%x" % address] status, _, _ = cij.ssh.command(cmd, shell=True) return status
def vblk_erase(self, address): """nvm_vblk erase""" cmd = ["nvm_vblk erase", self.envs, "0x%x" % address] status, _, _ = cij.ssh.command(cmd, shell=True) return status
[ "nvm_vblk", "erase" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L117-L121
[ "def", "vblk_erase", "(", "self", ",", "address", ")", ":", "cmd", "=", "[", "\"nvm_vblk erase\"", ",", "self", ".", "envs", ",", "\"0x%x\"", "%", "address", "]", "status", ",", "_", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "return", "status" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
Spdk.slc_erase
slc erase
deprecated/modules/cij/spdk.py
def slc_erase(self, address, BE_ID=0x1, PMODE=0x0100): """slc erase""" cmd = ["NVM_CLI_BE_ID=0x%x" % BE_ID, "NVM_CLI_PMODE=0x%x" % PMODE, "nvm_cmd erase", self.envs, "0x%x" % address] status, _, _ = cij.ssh.command(cmd, shell=True) return status
def slc_erase(self, address, BE_ID=0x1, PMODE=0x0100): """slc erase""" cmd = ["NVM_CLI_BE_ID=0x%x" % BE_ID, "NVM_CLI_PMODE=0x%x" % PMODE, "nvm_cmd erase", self.envs, "0x%x" % address] status, _, _ = cij.ssh.command(cmd, shell=True) return status
[ "slc", "erase" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/deprecated/modules/cij/spdk.py#L205-L209
[ "def", "slc_erase", "(", "self", ",", "address", ",", "BE_ID", "=", "0x1", ",", "PMODE", "=", "0x0100", ")", ":", "cmd", "=", "[", "\"NVM_CLI_BE_ID=0x%x\"", "%", "BE_ID", ",", "\"NVM_CLI_PMODE=0x%x\"", "%", "PMODE", ",", "\"nvm_cmd erase\"", ",", "self", ".", "envs", ",", "\"0x%x\"", "%", "address", "]", "status", ",", "_", ",", "_", "=", "cij", ".", "ssh", ".", "command", "(", "cmd", ",", "shell", "=", "True", ")", "return", "status" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
env
Verify BLOCK variables and construct exported variables
modules/cij/block.py
def env(): """Verify BLOCK variables and construct exported variables""" if cij.ssh.env(): cij.err("cij.block.env: invalid SSH environment") return 1 block = cij.env_to_dict(PREFIX, REQUIRED) block["DEV_PATH"] = "/dev/%s" % block["DEV_NAME"] cij.env_export(PREFIX, EXPORTED, block) return 0
def env(): """Verify BLOCK variables and construct exported variables""" if cij.ssh.env(): cij.err("cij.block.env: invalid SSH environment") return 1 block = cij.env_to_dict(PREFIX, REQUIRED) block["DEV_PATH"] = "/dev/%s" % block["DEV_NAME"] cij.env_export(PREFIX, EXPORTED, block) return 0
[ "Verify", "BLOCK", "variables", "and", "construct", "exported", "variables" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/block.py#L13-L26
[ "def", "env", "(", ")", ":", "if", "cij", ".", "ssh", ".", "env", "(", ")", ":", "cij", ".", "err", "(", "\"cij.block.env: invalid SSH environment\"", ")", "return", "1", "block", "=", "cij", ".", "env_to_dict", "(", "PREFIX", ",", "REQUIRED", ")", "block", "[", "\"DEV_PATH\"", "]", "=", "\"/dev/%s\"", "%", "block", "[", "\"DEV_NAME\"", "]", "cij", ".", "env_export", "(", "PREFIX", ",", "EXPORTED", ",", "block", ")", "return", "0" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
script_run
Execute a script or testcase
modules/cij/runner.py
def script_run(trun, script): """Execute a script or testcase""" if trun["conf"]["VERBOSE"]: cij.emph("rnr:script:run { script: %s }" % script) cij.emph("rnr:script:run:evars: %s" % script["evars"]) launchers = { ".py": "python", ".sh": "source" } ext = os.path.splitext(script["fpath"])[-1] if not ext in launchers.keys(): cij.err("rnr:script:run { invalid script[\"fpath\"]: %r }" % script["fpath"]) return 1 launch = launchers[ext] with open(script["log_fpath"], "a") as log_fd: log_fd.write("# script_fpath: %r\n" % script["fpath"]) log_fd.flush() bgn = time.time() cmd = [ 'bash', '-c', 'CIJ_ROOT=$(cij_root) && ' 'source $CIJ_ROOT/modules/cijoe.sh && ' 'source %s && ' 'CIJ_TEST_RES_ROOT="%s" %s %s ' % ( trun["conf"]["ENV_FPATH"], script["res_root"], launch, script["fpath"] ) ] if trun["conf"]["VERBOSE"] > 1: cij.emph("rnr:script:run { cmd: %r }" % " ".join(cmd)) evars = os.environ.copy() evars.update({k: str(script["evars"][k]) for k in script["evars"]}) process = Popen( cmd, stdout=log_fd, stderr=STDOUT, cwd=script["res_root"], env=evars ) process.wait() script["rcode"] = process.returncode script["wallc"] = time.time() - bgn if trun["conf"]["VERBOSE"]: cij.emph("rnr:script:run { wallc: %02f }" % script["wallc"]) cij.emph( "rnr:script:run { rcode: %r } " % script["rcode"], script["rcode"] ) return script["rcode"]
def script_run(trun, script): """Execute a script or testcase""" if trun["conf"]["VERBOSE"]: cij.emph("rnr:script:run { script: %s }" % script) cij.emph("rnr:script:run:evars: %s" % script["evars"]) launchers = { ".py": "python", ".sh": "source" } ext = os.path.splitext(script["fpath"])[-1] if not ext in launchers.keys(): cij.err("rnr:script:run { invalid script[\"fpath\"]: %r }" % script["fpath"]) return 1 launch = launchers[ext] with open(script["log_fpath"], "a") as log_fd: log_fd.write("# script_fpath: %r\n" % script["fpath"]) log_fd.flush() bgn = time.time() cmd = [ 'bash', '-c', 'CIJ_ROOT=$(cij_root) && ' 'source $CIJ_ROOT/modules/cijoe.sh && ' 'source %s && ' 'CIJ_TEST_RES_ROOT="%s" %s %s ' % ( trun["conf"]["ENV_FPATH"], script["res_root"], launch, script["fpath"] ) ] if trun["conf"]["VERBOSE"] > 1: cij.emph("rnr:script:run { cmd: %r }" % " ".join(cmd)) evars = os.environ.copy() evars.update({k: str(script["evars"][k]) for k in script["evars"]}) process = Popen( cmd, stdout=log_fd, stderr=STDOUT, cwd=script["res_root"], env=evars ) process.wait() script["rcode"] = process.returncode script["wallc"] = time.time() - bgn if trun["conf"]["VERBOSE"]: cij.emph("rnr:script:run { wallc: %02f }" % script["wallc"]) cij.emph( "rnr:script:run { rcode: %r } " % script["rcode"], script["rcode"] ) return script["rcode"]
[ "Execute", "a", "script", "or", "testcase" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L115-L176
[ "def", "script_run", "(", "trun", ",", "script", ")", ":", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:script:run { script: %s }\"", "%", "script", ")", "cij", ".", "emph", "(", "\"rnr:script:run:evars: %s\"", "%", "script", "[", "\"evars\"", "]", ")", "launchers", "=", "{", "\".py\"", ":", "\"python\"", ",", "\".sh\"", ":", "\"source\"", "}", "ext", "=", "os", ".", "path", ".", "splitext", "(", "script", "[", "\"fpath\"", "]", ")", "[", "-", "1", "]", "if", "not", "ext", "in", "launchers", ".", "keys", "(", ")", ":", "cij", ".", "err", "(", "\"rnr:script:run { invalid script[\\\"fpath\\\"]: %r }\"", "%", "script", "[", "\"fpath\"", "]", ")", "return", "1", "launch", "=", "launchers", "[", "ext", "]", "with", "open", "(", "script", "[", "\"log_fpath\"", "]", ",", "\"a\"", ")", "as", "log_fd", ":", "log_fd", ".", "write", "(", "\"# script_fpath: %r\\n\"", "%", "script", "[", "\"fpath\"", "]", ")", "log_fd", ".", "flush", "(", ")", "bgn", "=", "time", ".", "time", "(", ")", "cmd", "=", "[", "'bash'", ",", "'-c'", ",", "'CIJ_ROOT=$(cij_root) && '", "'source $CIJ_ROOT/modules/cijoe.sh && '", "'source %s && '", "'CIJ_TEST_RES_ROOT=\"%s\" %s %s '", "%", "(", "trun", "[", "\"conf\"", "]", "[", "\"ENV_FPATH\"", "]", ",", "script", "[", "\"res_root\"", "]", ",", "launch", ",", "script", "[", "\"fpath\"", "]", ")", "]", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ">", "1", ":", "cij", ".", "emph", "(", "\"rnr:script:run { cmd: %r }\"", "%", "\" \"", ".", "join", "(", "cmd", ")", ")", "evars", "=", "os", ".", "environ", ".", "copy", "(", ")", "evars", ".", "update", "(", "{", "k", ":", "str", "(", "script", "[", "\"evars\"", "]", "[", "k", "]", ")", "for", "k", "in", "script", "[", "\"evars\"", "]", "}", ")", "process", "=", "Popen", "(", "cmd", ",", "stdout", "=", "log_fd", ",", "stderr", "=", "STDOUT", ",", "cwd", "=", "script", "[", "\"res_root\"", "]", ",", "env", "=", "evars", ")", "process", ".", "wait", "(", ")", "script", "[", "\"rcode\"", "]", "=", "process", ".", "returncode", "script", "[", "\"wallc\"", "]", "=", "time", ".", "time", "(", ")", "-", "bgn", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:script:run { wallc: %02f }\"", "%", "script", "[", "\"wallc\"", "]", ")", "cij", ".", "emph", "(", "\"rnr:script:run { rcode: %r } \"", "%", "script", "[", "\"rcode\"", "]", ",", "script", "[", "\"rcode\"", "]", ")", "return", "script", "[", "\"rcode\"", "]" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
hook_setup
Setup hook
modules/cij/runner.py
def hook_setup(parent, hook_fpath): """Setup hook""" hook = copy.deepcopy(HOOK) hook["name"] = os.path.splitext(os.path.basename(hook_fpath))[0] hook["name"] = hook["name"].replace("_enter", "").replace("_exit", "") hook["res_root"] = parent["res_root"] hook["fpath_orig"] = hook_fpath hook["fname"] = "hook_%s" % os.path.basename(hook["fpath_orig"]) hook["fpath"] = os.sep.join([hook["res_root"], hook["fname"]]) hook["log_fpath"] = os.sep.join([ hook["res_root"], "%s.log" % hook["fname"] ]) hook["evars"].update(copy.deepcopy(parent["evars"])) shutil.copyfile(hook["fpath_orig"], hook["fpath"]) return hook
def hook_setup(parent, hook_fpath): """Setup hook""" hook = copy.deepcopy(HOOK) hook["name"] = os.path.splitext(os.path.basename(hook_fpath))[0] hook["name"] = hook["name"].replace("_enter", "").replace("_exit", "") hook["res_root"] = parent["res_root"] hook["fpath_orig"] = hook_fpath hook["fname"] = "hook_%s" % os.path.basename(hook["fpath_orig"]) hook["fpath"] = os.sep.join([hook["res_root"], hook["fname"]]) hook["log_fpath"] = os.sep.join([ hook["res_root"], "%s.log" % hook["fname"] ]) hook["evars"].update(copy.deepcopy(parent["evars"])) shutil.copyfile(hook["fpath_orig"], hook["fpath"]) return hook
[ "Setup", "hook" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L178-L197
[ "def", "hook_setup", "(", "parent", ",", "hook_fpath", ")", ":", "hook", "=", "copy", ".", "deepcopy", "(", "HOOK", ")", "hook", "[", "\"name\"", "]", "=", "os", ".", "path", ".", "splitext", "(", "os", ".", "path", ".", "basename", "(", "hook_fpath", ")", ")", "[", "0", "]", "hook", "[", "\"name\"", "]", "=", "hook", "[", "\"name\"", "]", ".", "replace", "(", "\"_enter\"", ",", "\"\"", ")", ".", "replace", "(", "\"_exit\"", ",", "\"\"", ")", "hook", "[", "\"res_root\"", "]", "=", "parent", "[", "\"res_root\"", "]", "hook", "[", "\"fpath_orig\"", "]", "=", "hook_fpath", "hook", "[", "\"fname\"", "]", "=", "\"hook_%s\"", "%", "os", ".", "path", ".", "basename", "(", "hook", "[", "\"fpath_orig\"", "]", ")", "hook", "[", "\"fpath\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "hook", "[", "\"res_root\"", "]", ",", "hook", "[", "\"fname\"", "]", "]", ")", "hook", "[", "\"log_fpath\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "hook", "[", "\"res_root\"", "]", ",", "\"%s.log\"", "%", "hook", "[", "\"fname\"", "]", "]", ")", "hook", "[", "\"evars\"", "]", ".", "update", "(", "copy", ".", "deepcopy", "(", "parent", "[", "\"evars\"", "]", ")", ")", "shutil", ".", "copyfile", "(", "hook", "[", "\"fpath_orig\"", "]", ",", "hook", "[", "\"fpath\"", "]", ")", "return", "hook" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
hooks_setup
Setup test-hooks @returns dict of hook filepaths {"enter": [], "exit": []}
modules/cij/runner.py
def hooks_setup(trun, parent, hnames=None): """ Setup test-hooks @returns dict of hook filepaths {"enter": [], "exit": []} """ hooks = { "enter": [], "exit": [] } if hnames is None: # Nothing to do, just return the struct return hooks for hname in hnames: # Fill out paths for med in HOOK_PATTERNS: for ptn in HOOK_PATTERNS[med]: fpath = os.sep.join([trun["conf"]["HOOKS"], ptn % hname]) if not os.path.exists(fpath): continue hook = hook_setup(parent, fpath) if not hook: continue hooks[med].append(hook) if not hooks["enter"] + hooks["exit"]: cij.err("rnr:hooks_setup:FAIL { hname: %r has no files }" % hname) return None return hooks
def hooks_setup(trun, parent, hnames=None): """ Setup test-hooks @returns dict of hook filepaths {"enter": [], "exit": []} """ hooks = { "enter": [], "exit": [] } if hnames is None: # Nothing to do, just return the struct return hooks for hname in hnames: # Fill out paths for med in HOOK_PATTERNS: for ptn in HOOK_PATTERNS[med]: fpath = os.sep.join([trun["conf"]["HOOKS"], ptn % hname]) if not os.path.exists(fpath): continue hook = hook_setup(parent, fpath) if not hook: continue hooks[med].append(hook) if not hooks["enter"] + hooks["exit"]: cij.err("rnr:hooks_setup:FAIL { hname: %r has no files }" % hname) return None return hooks
[ "Setup", "test", "-", "hooks" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L199-L230
[ "def", "hooks_setup", "(", "trun", ",", "parent", ",", "hnames", "=", "None", ")", ":", "hooks", "=", "{", "\"enter\"", ":", "[", "]", ",", "\"exit\"", ":", "[", "]", "}", "if", "hnames", "is", "None", ":", "# Nothing to do, just return the struct", "return", "hooks", "for", "hname", "in", "hnames", ":", "# Fill out paths", "for", "med", "in", "HOOK_PATTERNS", ":", "for", "ptn", "in", "HOOK_PATTERNS", "[", "med", "]", ":", "fpath", "=", "os", ".", "sep", ".", "join", "(", "[", "trun", "[", "\"conf\"", "]", "[", "\"HOOKS\"", "]", ",", "ptn", "%", "hname", "]", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "fpath", ")", ":", "continue", "hook", "=", "hook_setup", "(", "parent", ",", "fpath", ")", "if", "not", "hook", ":", "continue", "hooks", "[", "med", "]", ".", "append", "(", "hook", ")", "if", "not", "hooks", "[", "\"enter\"", "]", "+", "hooks", "[", "\"exit\"", "]", ":", "cij", ".", "err", "(", "\"rnr:hooks_setup:FAIL { hname: %r has no files }\"", "%", "hname", ")", "return", "None", "return", "hooks" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
trun_to_file
Dump the given trun to file
modules/cij/runner.py
def trun_to_file(trun, fpath=None): """Dump the given trun to file""" if fpath is None: fpath = yml_fpath(trun["conf"]["OUTPUT"]) with open(fpath, 'w') as yml_file: data = yaml.dump(trun, explicit_start=True, default_flow_style=False) yml_file.write(data)
def trun_to_file(trun, fpath=None): """Dump the given trun to file""" if fpath is None: fpath = yml_fpath(trun["conf"]["OUTPUT"]) with open(fpath, 'w') as yml_file: data = yaml.dump(trun, explicit_start=True, default_flow_style=False) yml_file.write(data)
[ "Dump", "the", "given", "trun", "to", "file" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L233-L241
[ "def", "trun_to_file", "(", "trun", ",", "fpath", "=", "None", ")", ":", "if", "fpath", "is", "None", ":", "fpath", "=", "yml_fpath", "(", "trun", "[", "\"conf\"", "]", "[", "\"OUTPUT\"", "]", ")", "with", "open", "(", "fpath", ",", "'w'", ")", "as", "yml_file", ":", "data", "=", "yaml", ".", "dump", "(", "trun", ",", "explicit_start", "=", "True", ",", "default_flow_style", "=", "False", ")", "yml_file", ".", "write", "(", "data", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
trun_emph
Print essential info on
modules/cij/runner.py
def trun_emph(trun): """Print essential info on""" if trun["conf"]["VERBOSE"] > 1: # Print environment variables cij.emph("rnr:CONF {") for cvar in sorted(trun["conf"].keys()): cij.emph(" % 16s: %r" % (cvar, trun["conf"][cvar])) cij.emph("}") if trun["conf"]["VERBOSE"]: cij.emph("rnr:INFO {") cij.emph(" OUTPUT: %r" % trun["conf"]["OUTPUT"]) cij.emph(" yml_fpath: %r" % yml_fpath(trun["conf"]["OUTPUT"])) cij.emph("}")
def trun_emph(trun): """Print essential info on""" if trun["conf"]["VERBOSE"] > 1: # Print environment variables cij.emph("rnr:CONF {") for cvar in sorted(trun["conf"].keys()): cij.emph(" % 16s: %r" % (cvar, trun["conf"][cvar])) cij.emph("}") if trun["conf"]["VERBOSE"]: cij.emph("rnr:INFO {") cij.emph(" OUTPUT: %r" % trun["conf"]["OUTPUT"]) cij.emph(" yml_fpath: %r" % yml_fpath(trun["conf"]["OUTPUT"])) cij.emph("}")
[ "Print", "essential", "info", "on" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L251-L264
[ "def", "trun_emph", "(", "trun", ")", ":", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ">", "1", ":", "# Print environment variables", "cij", ".", "emph", "(", "\"rnr:CONF {\"", ")", "for", "cvar", "in", "sorted", "(", "trun", "[", "\"conf\"", "]", ".", "keys", "(", ")", ")", ":", "cij", ".", "emph", "(", "\" % 16s: %r\"", "%", "(", "cvar", ",", "trun", "[", "\"conf\"", "]", "[", "cvar", "]", ")", ")", "cij", ".", "emph", "(", "\"}\"", ")", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:INFO {\"", ")", "cij", ".", "emph", "(", "\" OUTPUT: %r\"", "%", "trun", "[", "\"conf\"", "]", "[", "\"OUTPUT\"", "]", ")", "cij", ".", "emph", "(", "\" yml_fpath: %r\"", "%", "yml_fpath", "(", "trun", "[", "\"conf\"", "]", "[", "\"OUTPUT\"", "]", ")", ")", "cij", ".", "emph", "(", "\"}\"", ")" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
tcase_setup
Create and initialize a testcase
modules/cij/runner.py
def tcase_setup(trun, parent, tcase_fname): """ Create and initialize a testcase """ #pylint: disable=locally-disabled, unused-argument case = copy.deepcopy(TESTCASE) case["fname"] = tcase_fname case["fpath_orig"] = os.sep.join([trun["conf"]["TESTCASES"], case["fname"]]) if not os.path.exists(case["fpath_orig"]): cij.err('rnr:tcase_setup: !case["fpath_orig"]: %r' % case["fpath_orig"]) return None case["name"] = os.path.splitext(case["fname"])[0] case["ident"] = "/".join([parent["ident"], case["fname"]]) case["res_root"] = os.sep.join([parent["res_root"], case["fname"]]) case["aux_root"] = os.sep.join([case["res_root"], "_aux"]) case["log_fpath"] = os.sep.join([case["res_root"], "run.log"]) case["fpath"] = os.sep.join([case["res_root"], case["fname"]]) case["evars"].update(copy.deepcopy(parent["evars"])) # Initalize os.makedirs(case["res_root"]) # Create DIRS os.makedirs(case["aux_root"]) shutil.copyfile(case["fpath_orig"], case["fpath"]) # Copy testcase # Initialize hooks case["hooks"] = hooks_setup(trun, case, parent.get("hooks_pr_tcase")) return case
def tcase_setup(trun, parent, tcase_fname): """ Create and initialize a testcase """ #pylint: disable=locally-disabled, unused-argument case = copy.deepcopy(TESTCASE) case["fname"] = tcase_fname case["fpath_orig"] = os.sep.join([trun["conf"]["TESTCASES"], case["fname"]]) if not os.path.exists(case["fpath_orig"]): cij.err('rnr:tcase_setup: !case["fpath_orig"]: %r' % case["fpath_orig"]) return None case["name"] = os.path.splitext(case["fname"])[0] case["ident"] = "/".join([parent["ident"], case["fname"]]) case["res_root"] = os.sep.join([parent["res_root"], case["fname"]]) case["aux_root"] = os.sep.join([case["res_root"], "_aux"]) case["log_fpath"] = os.sep.join([case["res_root"], "run.log"]) case["fpath"] = os.sep.join([case["res_root"], case["fname"]]) case["evars"].update(copy.deepcopy(parent["evars"])) # Initalize os.makedirs(case["res_root"]) # Create DIRS os.makedirs(case["aux_root"]) shutil.copyfile(case["fpath_orig"], case["fpath"]) # Copy testcase # Initialize hooks case["hooks"] = hooks_setup(trun, case, parent.get("hooks_pr_tcase")) return case
[ "Create", "and", "initialize", "a", "testcase" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L267-L301
[ "def", "tcase_setup", "(", "trun", ",", "parent", ",", "tcase_fname", ")", ":", "#pylint: disable=locally-disabled, unused-argument", "case", "=", "copy", ".", "deepcopy", "(", "TESTCASE", ")", "case", "[", "\"fname\"", "]", "=", "tcase_fname", "case", "[", "\"fpath_orig\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "trun", "[", "\"conf\"", "]", "[", "\"TESTCASES\"", "]", ",", "case", "[", "\"fname\"", "]", "]", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "case", "[", "\"fpath_orig\"", "]", ")", ":", "cij", ".", "err", "(", "'rnr:tcase_setup: !case[\"fpath_orig\"]: %r'", "%", "case", "[", "\"fpath_orig\"", "]", ")", "return", "None", "case", "[", "\"name\"", "]", "=", "os", ".", "path", ".", "splitext", "(", "case", "[", "\"fname\"", "]", ")", "[", "0", "]", "case", "[", "\"ident\"", "]", "=", "\"/\"", ".", "join", "(", "[", "parent", "[", "\"ident\"", "]", ",", "case", "[", "\"fname\"", "]", "]", ")", "case", "[", "\"res_root\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "parent", "[", "\"res_root\"", "]", ",", "case", "[", "\"fname\"", "]", "]", ")", "case", "[", "\"aux_root\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "case", "[", "\"res_root\"", "]", ",", "\"_aux\"", "]", ")", "case", "[", "\"log_fpath\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "case", "[", "\"res_root\"", "]", ",", "\"run.log\"", "]", ")", "case", "[", "\"fpath\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "case", "[", "\"res_root\"", "]", ",", "case", "[", "\"fname\"", "]", "]", ")", "case", "[", "\"evars\"", "]", ".", "update", "(", "copy", ".", "deepcopy", "(", "parent", "[", "\"evars\"", "]", ")", ")", "# Initalize", "os", ".", "makedirs", "(", "case", "[", "\"res_root\"", "]", ")", "# Create DIRS", "os", ".", "makedirs", "(", "case", "[", "\"aux_root\"", "]", ")", "shutil", ".", "copyfile", "(", "case", "[", "\"fpath_orig\"", "]", ",", "case", "[", "\"fpath\"", "]", ")", "# Copy testcase", "# Initialize hooks", "case", "[", "\"hooks\"", "]", "=", "hooks_setup", "(", "trun", ",", "case", ",", "parent", ".", "get", "(", "\"hooks_pr_tcase\"", ")", ")", "return", "case" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
tsuite_exit
Triggers when exiting the given testsuite
modules/cij/runner.py
def tsuite_exit(trun, tsuite): """Triggers when exiting the given testsuite""" if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:exit") rcode = 0 for hook in reversed(tsuite["hooks"]["exit"]): # EXIT-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:exit { rcode: %r } " % rcode, rcode) return rcode
def tsuite_exit(trun, tsuite): """Triggers when exiting the given testsuite""" if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:exit") rcode = 0 for hook in reversed(tsuite["hooks"]["exit"]): # EXIT-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:exit { rcode: %r } " % rcode, rcode) return rcode
[ "Triggers", "when", "exiting", "the", "given", "testsuite" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L304-L319
[ "def", "tsuite_exit", "(", "trun", ",", "tsuite", ")", ":", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tsuite:exit\"", ")", "rcode", "=", "0", "for", "hook", "in", "reversed", "(", "tsuite", "[", "\"hooks\"", "]", "[", "\"exit\"", "]", ")", ":", "# EXIT-hooks", "rcode", "=", "script_run", "(", "trun", ",", "hook", ")", "if", "rcode", ":", "break", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tsuite:exit { rcode: %r } \"", "%", "rcode", ",", "rcode", ")", "return", "rcode" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
tsuite_enter
Triggers when entering the given testsuite
modules/cij/runner.py
def tsuite_enter(trun, tsuite): """Triggers when entering the given testsuite""" if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:enter { name: %r }" % tsuite["name"]) rcode = 0 for hook in tsuite["hooks"]["enter"]: # ENTER-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:enter { rcode: %r } " % rcode, rcode) return rcode
def tsuite_enter(trun, tsuite): """Triggers when entering the given testsuite""" if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:enter { name: %r }" % tsuite["name"]) rcode = 0 for hook in tsuite["hooks"]["enter"]: # ENTER-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tsuite:enter { rcode: %r } " % rcode, rcode) return rcode
[ "Triggers", "when", "entering", "the", "given", "testsuite" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L322-L337
[ "def", "tsuite_enter", "(", "trun", ",", "tsuite", ")", ":", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tsuite:enter { name: %r }\"", "%", "tsuite", "[", "\"name\"", "]", ")", "rcode", "=", "0", "for", "hook", "in", "tsuite", "[", "\"hooks\"", "]", "[", "\"enter\"", "]", ":", "# ENTER-hooks", "rcode", "=", "script_run", "(", "trun", ",", "hook", ")", "if", "rcode", ":", "break", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tsuite:enter { rcode: %r } \"", "%", "rcode", ",", "rcode", ")", "return", "rcode" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
tsuite_setup
Creates and initialized a TESTSUITE struct and site-effects such as creating output directories and forwarding initialization of testcases
modules/cij/runner.py
def tsuite_setup(trun, declr, enum): """ Creates and initialized a TESTSUITE struct and site-effects such as creating output directories and forwarding initialization of testcases """ suite = copy.deepcopy(TESTSUITE) # Setup the test-suite suite["name"] = declr.get("name") if suite["name"] is None: cij.err("rnr:tsuite_setup: no testsuite is given") return None suite["alias"] = declr.get("alias") suite["ident"] = "%s_%d" % (suite["name"], enum) suite["res_root"] = os.sep.join([trun["conf"]["OUTPUT"], suite["ident"]]) suite["aux_root"] = os.sep.join([suite["res_root"], "_aux"]) suite["evars"].update(copy.deepcopy(trun["evars"])) suite["evars"].update(copy.deepcopy(declr.get("evars", {}))) # Initialize os.makedirs(suite["res_root"]) os.makedirs(suite["aux_root"]) # Setup testsuite-hooks suite["hooks"] = hooks_setup(trun, suite, declr.get("hooks")) # Forward from declaration suite["hooks_pr_tcase"] = declr.get("hooks_pr_tcase", []) suite["fname"] = "%s.suite" % suite["name"] suite["fpath"] = os.sep.join([trun["conf"]["TESTSUITES"], suite["fname"]]) # # Load testcases from .suite file OR from declaration # tcase_fpaths = [] # Load testcase fpaths if os.path.exists(suite["fpath"]): # From suite-file suite_lines = ( l.strip() for l in open(suite["fpath"]).read().splitlines() ) tcase_fpaths.extend( (l for l in suite_lines if len(l) > 1 and l[0] != "#") ) else: # From declaration tcase_fpaths.extend(declr.get("testcases", [])) # NOTE: fix duplicates; allow them # NOTE: Currently hot-fixed here if len(set(tcase_fpaths)) != len(tcase_fpaths): cij.err("rnr:suite: failed: duplicate tcase in suite not supported") return None for tcase_fname in tcase_fpaths: # Setup testcases tcase = tcase_setup(trun, suite, tcase_fname) if not tcase: cij.err("rnr:suite: failed: tcase_setup") return None suite["testcases"].append(tcase) return suite
def tsuite_setup(trun, declr, enum): """ Creates and initialized a TESTSUITE struct and site-effects such as creating output directories and forwarding initialization of testcases """ suite = copy.deepcopy(TESTSUITE) # Setup the test-suite suite["name"] = declr.get("name") if suite["name"] is None: cij.err("rnr:tsuite_setup: no testsuite is given") return None suite["alias"] = declr.get("alias") suite["ident"] = "%s_%d" % (suite["name"], enum) suite["res_root"] = os.sep.join([trun["conf"]["OUTPUT"], suite["ident"]]) suite["aux_root"] = os.sep.join([suite["res_root"], "_aux"]) suite["evars"].update(copy.deepcopy(trun["evars"])) suite["evars"].update(copy.deepcopy(declr.get("evars", {}))) # Initialize os.makedirs(suite["res_root"]) os.makedirs(suite["aux_root"]) # Setup testsuite-hooks suite["hooks"] = hooks_setup(trun, suite, declr.get("hooks")) # Forward from declaration suite["hooks_pr_tcase"] = declr.get("hooks_pr_tcase", []) suite["fname"] = "%s.suite" % suite["name"] suite["fpath"] = os.sep.join([trun["conf"]["TESTSUITES"], suite["fname"]]) # # Load testcases from .suite file OR from declaration # tcase_fpaths = [] # Load testcase fpaths if os.path.exists(suite["fpath"]): # From suite-file suite_lines = ( l.strip() for l in open(suite["fpath"]).read().splitlines() ) tcase_fpaths.extend( (l for l in suite_lines if len(l) > 1 and l[0] != "#") ) else: # From declaration tcase_fpaths.extend(declr.get("testcases", [])) # NOTE: fix duplicates; allow them # NOTE: Currently hot-fixed here if len(set(tcase_fpaths)) != len(tcase_fpaths): cij.err("rnr:suite: failed: duplicate tcase in suite not supported") return None for tcase_fname in tcase_fpaths: # Setup testcases tcase = tcase_setup(trun, suite, tcase_fname) if not tcase: cij.err("rnr:suite: failed: tcase_setup") return None suite["testcases"].append(tcase) return suite
[ "Creates", "and", "initialized", "a", "TESTSUITE", "struct", "and", "site", "-", "effects", "such", "as", "creating", "output", "directories", "and", "forwarding", "initialization", "of", "testcases" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L339-L402
[ "def", "tsuite_setup", "(", "trun", ",", "declr", ",", "enum", ")", ":", "suite", "=", "copy", ".", "deepcopy", "(", "TESTSUITE", ")", "# Setup the test-suite", "suite", "[", "\"name\"", "]", "=", "declr", ".", "get", "(", "\"name\"", ")", "if", "suite", "[", "\"name\"", "]", "is", "None", ":", "cij", ".", "err", "(", "\"rnr:tsuite_setup: no testsuite is given\"", ")", "return", "None", "suite", "[", "\"alias\"", "]", "=", "declr", ".", "get", "(", "\"alias\"", ")", "suite", "[", "\"ident\"", "]", "=", "\"%s_%d\"", "%", "(", "suite", "[", "\"name\"", "]", ",", "enum", ")", "suite", "[", "\"res_root\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "trun", "[", "\"conf\"", "]", "[", "\"OUTPUT\"", "]", ",", "suite", "[", "\"ident\"", "]", "]", ")", "suite", "[", "\"aux_root\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "suite", "[", "\"res_root\"", "]", ",", "\"_aux\"", "]", ")", "suite", "[", "\"evars\"", "]", ".", "update", "(", "copy", ".", "deepcopy", "(", "trun", "[", "\"evars\"", "]", ")", ")", "suite", "[", "\"evars\"", "]", ".", "update", "(", "copy", ".", "deepcopy", "(", "declr", ".", "get", "(", "\"evars\"", ",", "{", "}", ")", ")", ")", "# Initialize", "os", ".", "makedirs", "(", "suite", "[", "\"res_root\"", "]", ")", "os", ".", "makedirs", "(", "suite", "[", "\"aux_root\"", "]", ")", "# Setup testsuite-hooks", "suite", "[", "\"hooks\"", "]", "=", "hooks_setup", "(", "trun", ",", "suite", ",", "declr", ".", "get", "(", "\"hooks\"", ")", ")", "# Forward from declaration", "suite", "[", "\"hooks_pr_tcase\"", "]", "=", "declr", ".", "get", "(", "\"hooks_pr_tcase\"", ",", "[", "]", ")", "suite", "[", "\"fname\"", "]", "=", "\"%s.suite\"", "%", "suite", "[", "\"name\"", "]", "suite", "[", "\"fpath\"", "]", "=", "os", ".", "sep", ".", "join", "(", "[", "trun", "[", "\"conf\"", "]", "[", "\"TESTSUITES\"", "]", ",", "suite", "[", "\"fname\"", "]", "]", ")", "#", "# Load testcases from .suite file OR from declaration", "#", "tcase_fpaths", "=", "[", "]", "# Load testcase fpaths", "if", "os", ".", "path", ".", "exists", "(", "suite", "[", "\"fpath\"", "]", ")", ":", "# From suite-file", "suite_lines", "=", "(", "l", ".", "strip", "(", ")", "for", "l", "in", "open", "(", "suite", "[", "\"fpath\"", "]", ")", ".", "read", "(", ")", ".", "splitlines", "(", ")", ")", "tcase_fpaths", ".", "extend", "(", "(", "l", "for", "l", "in", "suite_lines", "if", "len", "(", "l", ")", ">", "1", "and", "l", "[", "0", "]", "!=", "\"#\"", ")", ")", "else", ":", "# From declaration", "tcase_fpaths", ".", "extend", "(", "declr", ".", "get", "(", "\"testcases\"", ",", "[", "]", ")", ")", "# NOTE: fix duplicates; allow them", "# NOTE: Currently hot-fixed here", "if", "len", "(", "set", "(", "tcase_fpaths", ")", ")", "!=", "len", "(", "tcase_fpaths", ")", ":", "cij", ".", "err", "(", "\"rnr:suite: failed: duplicate tcase in suite not supported\"", ")", "return", "None", "for", "tcase_fname", "in", "tcase_fpaths", ":", "# Setup testcases", "tcase", "=", "tcase_setup", "(", "trun", ",", "suite", ",", "tcase_fname", ")", "if", "not", "tcase", ":", "cij", ".", "err", "(", "\"rnr:suite: failed: tcase_setup\"", ")", "return", "None", "suite", "[", "\"testcases\"", "]", ".", "append", "(", "tcase", ")", "return", "suite" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
tcase_exit
...
modules/cij/runner.py
def tcase_exit(trun, tsuite, tcase): """...""" #pylint: disable=locally-disabled, unused-argument if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:exit { fname: %r }" % tcase["fname"]) rcode = 0 for hook in reversed(tcase["hooks"]["exit"]): # tcase EXIT-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:exit { rcode: %r }" % rcode, rcode) return rcode
def tcase_exit(trun, tsuite, tcase): """...""" #pylint: disable=locally-disabled, unused-argument if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:exit { fname: %r }" % tcase["fname"]) rcode = 0 for hook in reversed(tcase["hooks"]["exit"]): # tcase EXIT-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:exit { rcode: %r }" % rcode, rcode) return rcode
[ "..." ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L405-L421
[ "def", "tcase_exit", "(", "trun", ",", "tsuite", ",", "tcase", ")", ":", "#pylint: disable=locally-disabled, unused-argument", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tcase:exit { fname: %r }\"", "%", "tcase", "[", "\"fname\"", "]", ")", "rcode", "=", "0", "for", "hook", "in", "reversed", "(", "tcase", "[", "\"hooks\"", "]", "[", "\"exit\"", "]", ")", ":", "# tcase EXIT-hooks", "rcode", "=", "script_run", "(", "trun", ",", "hook", ")", "if", "rcode", ":", "break", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tcase:exit { rcode: %r }\"", "%", "rcode", ",", "rcode", ")", "return", "rcode" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379
valid
tcase_enter
setup res_root and aux_root, log info and run tcase-enter-hooks @returns 0 when all hooks succeed, some value othervise
modules/cij/runner.py
def tcase_enter(trun, tsuite, tcase): """ setup res_root and aux_root, log info and run tcase-enter-hooks @returns 0 when all hooks succeed, some value othervise """ #pylint: disable=locally-disabled, unused-argument if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:enter") cij.emph("rnr:tcase:enter { fname: %r }" % tcase["fname"]) cij.emph("rnr:tcase:enter { log_fpath: %r }" % tcase["log_fpath"]) rcode = 0 for hook in tcase["hooks"]["enter"]: # tcase ENTER-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:exit: { rcode: %r }" % rcode, rcode) return rcode
def tcase_enter(trun, tsuite, tcase): """ setup res_root and aux_root, log info and run tcase-enter-hooks @returns 0 when all hooks succeed, some value othervise """ #pylint: disable=locally-disabled, unused-argument if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:enter") cij.emph("rnr:tcase:enter { fname: %r }" % tcase["fname"]) cij.emph("rnr:tcase:enter { log_fpath: %r }" % tcase["log_fpath"]) rcode = 0 for hook in tcase["hooks"]["enter"]: # tcase ENTER-hooks rcode = script_run(trun, hook) if rcode: break if trun["conf"]["VERBOSE"]: cij.emph("rnr:tcase:exit: { rcode: %r }" % rcode, rcode) return rcode
[ "setup", "res_root", "and", "aux_root", "log", "info", "and", "run", "tcase", "-", "enter", "-", "hooks" ]
refenv/cijoe
python
https://github.com/refenv/cijoe/blob/21d7b2ed4ff68e0a1457e7df2db27f6334f1a379/modules/cij/runner.py#L424-L446
[ "def", "tcase_enter", "(", "trun", ",", "tsuite", ",", "tcase", ")", ":", "#pylint: disable=locally-disabled, unused-argument", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tcase:enter\"", ")", "cij", ".", "emph", "(", "\"rnr:tcase:enter { fname: %r }\"", "%", "tcase", "[", "\"fname\"", "]", ")", "cij", ".", "emph", "(", "\"rnr:tcase:enter { log_fpath: %r }\"", "%", "tcase", "[", "\"log_fpath\"", "]", ")", "rcode", "=", "0", "for", "hook", "in", "tcase", "[", "\"hooks\"", "]", "[", "\"enter\"", "]", ":", "# tcase ENTER-hooks", "rcode", "=", "script_run", "(", "trun", ",", "hook", ")", "if", "rcode", ":", "break", "if", "trun", "[", "\"conf\"", "]", "[", "\"VERBOSE\"", "]", ":", "cij", ".", "emph", "(", "\"rnr:tcase:exit: { rcode: %r }\"", "%", "rcode", ",", "rcode", ")", "return", "rcode" ]
21d7b2ed4ff68e0a1457e7df2db27f6334f1a379