From 291d65070daad76846d804f7bbd1c36ab02feb34 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 28 Feb 2019 18:54:37 -0300 Subject: [PATCH] move common schema values to constants.py --- lbrynet/extras/wallet/manager.py | 2 +- lbrynet/schema/address.py | 2 +- lbrynet/schema/base.py | 2 +- lbrynet/schema/claim.py | 3 +- lbrynet/schema/constants.py | 58 +++++++++++++++++++ lbrynet/schema/fee.py | 2 +- lbrynet/schema/legacy_schema_v1/__init__.py | 58 ------------------- .../schema/legacy_schema_v1/certificate.py | 3 +- lbrynet/schema/legacy_schema_v1/fee.py | 3 +- lbrynet/schema/legacy_schema_v1/signature.py | 3 +- lbrynet/schema/signer.py | 2 +- lbrynet/schema/validator.py | 2 +- tests/unit/schema/test_lbryschema.py | 2 +- 13 files changed, 73 insertions(+), 69 deletions(-) create mode 100644 lbrynet/schema/constants.py diff --git a/lbrynet/extras/wallet/manager.py b/lbrynet/extras/wallet/manager.py index d8638671c..577b39847 100644 --- a/lbrynet/extras/wallet/manager.py +++ b/lbrynet/extras/wallet/manager.py @@ -6,7 +6,7 @@ from binascii import unhexlify from datetime import datetime from typing import Optional -from lbrynet.schema.legacy_schema_v1 import SECP256k1 +from lbrynet.schema.constants import SECP256k1 from torba.client.basemanager import BaseWalletManager from torba.rpc.jsonrpc import CodeMessageError diff --git a/lbrynet/schema/address.py b/lbrynet/schema/address.py index 5017122ff..46e94d95e 100644 --- a/lbrynet/schema/address.py +++ b/lbrynet/schema/address.py @@ -2,7 +2,7 @@ import lbrynet.schema from lbrynet.schema.base import b58encode, b58decode, validate_b58_checksum from lbrynet.schema.hashing import double_sha256, hash160 from lbrynet.schema.error import InvalidAddress -from lbrynet.schema.legacy_schema_v1 import ADDRESS_LENGTH, ADDRESS_PREFIXES, PUBKEY_ADDRESS, SCRIPT_ADDRESS +from lbrynet.schema.constants import ADDRESS_LENGTH, ADDRESS_PREFIXES, PUBKEY_ADDRESS, SCRIPT_ADDRESS def validate_address_length(addr_bytes): diff --git a/lbrynet/schema/base.py b/lbrynet/schema/base.py index e39aefdf5..db89c93cd 100644 --- a/lbrynet/schema/base.py +++ b/lbrynet/schema/base.py @@ -1,4 +1,4 @@ -from lbrynet.schema.legacy_schema_v1 import ADDRESS_CHECKSUM_LENGTH +from lbrynet.schema.constants import ADDRESS_CHECKSUM_LENGTH from lbrynet.schema.hashing import double_sha256 from lbrynet.schema.error import InvalidAddress diff --git a/lbrynet/schema/claim.py b/lbrynet/schema/claim.py index 17b5b0354..6a8eaec90 100644 --- a/lbrynet/schema/claim.py +++ b/lbrynet/schema/claim.py @@ -10,7 +10,8 @@ from lbrynet.schema.signature import Signature from lbrynet.schema.validator import get_validator from lbrynet.schema.signer import get_signer from lbrynet.schema.legacy_schema_v1.claim import Claim -from lbrynet.schema.legacy_schema_v1 import CURVE_NAMES, CLAIM_TYPE_NAMES, SECP256k1 +from lbrynet.schema.legacy_schema_v1 import CLAIM_TYPE_NAMES +from lbrynet.schema.constants import CURVE_NAMES, SECP256k1 from lbrynet.schema.encoding import decode_fields, decode_b64_fields, encode_fields from lbrynet.schema.error import DecodeError from lbrynet.schema.fee import Fee diff --git a/lbrynet/schema/constants.py b/lbrynet/schema/constants.py new file mode 100644 index 000000000..7866eafaa --- /dev/null +++ b/lbrynet/schema/constants.py @@ -0,0 +1,58 @@ +LBC = "LBC" +BTC = "BTC" +USD = "USD" + +CURRENCY_MAP = { + LBC: 1, + BTC: 2, + USD: 3 +} + +CURRENCY_NAMES = { + 1: LBC, + 2: BTC, + 3: USD +} + +ADDRESS_LENGTH = 25 +ADDRESS_CHECKSUM_LENGTH = 4 +NIST256p = "NIST256p" +NIST384p = "NIST384p" +SECP256k1 = "SECP256k1" + +ECDSA_CURVES = { + NIST256p: 1, + NIST384p: 2, + SECP256k1: 3 +} + +CURVE_NAMES = { + 1: NIST256p, + 2: NIST384p, + 3: SECP256k1 +} + +SHA256 = "sha256" +SHA384 = "sha384" + + +B58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' +assert len(B58_CHARS) == 58 + +PUBKEY_ADDRESS = 0 +SCRIPT_ADDRESS = 5 + +ADDRESS_PREFIXES = { + "lbrycrd_main": { + PUBKEY_ADDRESS: 85, + SCRIPT_ADDRESS: 122 + }, + "lbrycrd_regtest": { + PUBKEY_ADDRESS: 111, + SCRIPT_ADDRESS: 196 + }, + "lbrycrd_testnet": { + PUBKEY_ADDRESS: 111, + SCRIPT_ADDRESS: 196 + }, +} diff --git a/lbrynet/schema/fee.py b/lbrynet/schema/fee.py index 8cfafadbb..53fb6fa34 100644 --- a/lbrynet/schema/fee.py +++ b/lbrynet/schema/fee.py @@ -1,7 +1,7 @@ from collections import OrderedDict from lbrynet.schema.address import encode_address, decode_address -from lbrynet.schema.legacy_schema_v1 import CURRENCY_NAMES, CURRENCY_MAP +from lbrynet.schema.constants import CURRENCY_NAMES, CURRENCY_MAP from lbrynet.schema.legacy_schema_v1.fee import Fee as FeeHelper from lbrynet.schema.proto2 import fee_pb2 diff --git a/lbrynet/schema/legacy_schema_v1/__init__.py b/lbrynet/schema/legacy_schema_v1/__init__.py index aeff1b4bc..4e075a447 100644 --- a/lbrynet/schema/legacy_schema_v1/__init__.py +++ b/lbrynet/schema/legacy_schema_v1/__init__.py @@ -18,24 +18,6 @@ VERSION_NAMES = { 4: V_0_1_0 } -LBC = "LBC" -BTC = "BTC" -USD = "USD" - -CURRENCY_MAP = { - LBC: 1, - BTC: 2, - USD: 3 -} - -CURRENCY_NAMES = { - 1: LBC, - 2: BTC, - 3: USD -} - -ADDRESS_LENGTH = 25 -ADDRESS_CHECKSUM_LENGTH = 4 VERSION = "version" STREAM_TYPE = "streamType" @@ -60,43 +42,3 @@ SOURCE_TYPES = { LBRY_SD_HASH: 1 } -NIST256p = "NIST256p" -NIST384p = "NIST384p" -SECP256k1 = "SECP256k1" - -ECDSA_CURVES = { - NIST256p: 1, - NIST384p: 2, - SECP256k1: 3 -} - -CURVE_NAMES = { - 1: NIST256p, - 2: NIST384p, - 3: SECP256k1 -} - -SHA256 = "sha256" -SHA384 = "sha384" - - -B58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' -assert len(B58_CHARS) == 58 - -PUBKEY_ADDRESS = 0 -SCRIPT_ADDRESS = 5 - -ADDRESS_PREFIXES = { - "lbrycrd_main": { - PUBKEY_ADDRESS: 85, - SCRIPT_ADDRESS: 122 - }, - "lbrycrd_regtest": { - PUBKEY_ADDRESS: 111, - SCRIPT_ADDRESS: 196 - }, - "lbrycrd_testnet": { - PUBKEY_ADDRESS: 111, - SCRIPT_ADDRESS: 196 - }, -} diff --git a/lbrynet/schema/legacy_schema_v1/certificate.py b/lbrynet/schema/legacy_schema_v1/certificate.py index 0ab8540ea..f71c034f3 100644 --- a/lbrynet/schema/legacy_schema_v1/certificate.py +++ b/lbrynet/schema/legacy_schema_v1/certificate.py @@ -2,7 +2,8 @@ from copy import deepcopy from lbrynet.schema.proto2 import certificate_pb2 as cert_pb from lbrynet.schema.legacy_schema_v1.schema import Schema -from lbrynet.schema.legacy_schema_v1 import VERSION_MAP, V_0_0_1, ECDSA_CURVES, CURVE_NAMES +from lbrynet.schema.legacy_schema_v1 import VERSION_MAP, V_0_0_1 +from lbrynet.schema.constants import ECDSA_CURVES, CURVE_NAMES from lbrynet.schema.validator import get_key_type_from_dem diff --git a/lbrynet/schema/legacy_schema_v1/fee.py b/lbrynet/schema/legacy_schema_v1/fee.py index e098492f6..b4ef93d2d 100644 --- a/lbrynet/schema/legacy_schema_v1/fee.py +++ b/lbrynet/schema/legacy_schema_v1/fee.py @@ -2,7 +2,8 @@ from copy import deepcopy from lbrynet.schema.proto2 import fee_pb2 as fee_pb from lbrynet.schema.legacy_schema_v1.schema import Schema -from lbrynet.schema.legacy_schema_v1 import VERSION_MAP, CURRENCY_MAP +from lbrynet.schema.legacy_schema_v1 import VERSION_MAP +from lbrynet.schema.constants import CURRENCY_MAP class Fee(Schema): diff --git a/lbrynet/schema/legacy_schema_v1/signature.py b/lbrynet/schema/legacy_schema_v1/signature.py index 20a3ed192..d14d5f473 100644 --- a/lbrynet/schema/legacy_schema_v1/signature.py +++ b/lbrynet/schema/legacy_schema_v1/signature.py @@ -1,7 +1,8 @@ from copy import deepcopy from lbrynet.schema.proto2 import signature_pb2 as signature_pb -from lbrynet.schema.legacy_schema_v1 import VERSION_MAP, ECDSA_CURVES +from lbrynet.schema.legacy_schema_v1 import VERSION_MAP +from lbrynet.schema.constants import ECDSA_CURVES from lbrynet.schema.legacy_schema_v1.schema import Schema diff --git a/lbrynet/schema/signer.py b/lbrynet/schema/signer.py index c3b07548d..4c9547e70 100644 --- a/lbrynet/schema/signer.py +++ b/lbrynet/schema/signer.py @@ -8,7 +8,7 @@ from lbrynet.schema.validator import validate_claim_id from lbrynet.schema.legacy_schema_v1.certificate import Certificate from lbrynet.schema.legacy_schema_v1.claim import Claim from lbrynet.schema.legacy_schema_v1 import V_0_0_1, CLAIM_TYPE, CLAIM_TYPES, CERTIFICATE_TYPE, VERSION -from lbrynet.schema.legacy_schema_v1 import NIST256p, NIST384p, SECP256k1, SHA256, SHA384 +from lbrynet.schema.constants import NIST256p, NIST384p, SECP256k1, SHA256, SHA384 class NIST_ECDSASigner(object): diff --git a/lbrynet/schema/validator.py b/lbrynet/schema/validator.py index 8a37bf974..1b30d1e20 100644 --- a/lbrynet/schema/validator.py +++ b/lbrynet/schema/validator.py @@ -13,7 +13,7 @@ from cryptography.exceptions import InvalidSignature from ecdsa.util import sigencode_der from lbrynet.schema.address import decode_address -from lbrynet.schema.legacy_schema_v1 import NIST256p, NIST384p, SECP256k1, ECDSA_CURVES, CURVE_NAMES +from lbrynet.schema.constants import NIST256p, NIST384p, SECP256k1, ECDSA_CURVES, CURVE_NAMES def validate_claim_id(claim_id): diff --git a/tests/unit/schema/test_lbryschema.py b/tests/unit/schema/test_lbryschema.py index 75a92a11c..e6cea8fa6 100644 --- a/tests/unit/schema/test_lbryschema.py +++ b/tests/unit/schema/test_lbryschema.py @@ -16,7 +16,7 @@ from .test_data import secp256k1_private_key, claim_010_signed_secp256k1, secp25 from .test_data import hex_encoded_003, decoded_hex_encoded_003, malformed_secp256k1_cert from lbrynet import schema from lbrynet.schema.claim import ClaimDict -from lbrynet.schema.legacy_schema_v1 import NIST256p, NIST384p, SECP256k1 +from lbrynet.schema.constants import NIST256p, NIST384p, SECP256k1 from lbrynet.schema.legacy.migrate import migrate from lbrynet.schema.signer import get_signer from lbrynet.schema.uri import URI, URIParseError