# Path: ngcccbase/address.py
# def coloraddress_to_bitcoinaddress(coloraddress):
#     if "@" not in coloraddress:
#         return coloraddress # already btcaddress
#     colorid, btcaddress = coloraddress.split("@")
#     return btcaddress


import re
import json
import csv
from decimal import Decimal
from ngcccbase.address import coloraddress_to_bitcoinaddress
    # limit basic string and ints for now
    if not re.match("^[a-zA-Z0-9_-]+$", value):
        raise InvalidInput("Invalid value!")
    return value


def colordesc(colordesc):
    if not re.match("^(epobc|obc):[0-9a-f]+:[0-9]+:[0-9]+$", colordesc):
        raise InvalidInput("Invalid color description!")
    return colordesc


def jsonasset(data):
    data = json.loads(data)
    monikers = [moniker(m) for m in data['monikers']]
    color_set = [colordesc(cd) for cd in data['color_set']]
    _unit = unit(data['unit'])
    return { 'monikers' : monikers, 'color_set' : color_set, 'unit' : _unit }


def coloraddress(model, asset, coloraddress):

    # asset must match address asset id
    adm = model.get_asset_definition_manager()
    address_asset, btcaddress = adm.get_asset_and_address(coloraddress)
    if asset != address_asset:
        raise InvalidInput("Address and asset don't match!")

    # check if valid btcaddress
    if not model.validate_address(btcaddress):

# Path: ngcccbase/address.py
# def coloraddress_to_bitcoinaddress(coloraddress):
#     if "@" not in coloraddress:
#         return coloraddress # already btcaddress
#     colorid, btcaddress = coloraddress.split("@")
#     return btcaddress


# Path: ngcccbase/sanitize.py
import re
import json
import csv
from decimal import Decimal
from ngcccbase.address import coloraddress_to_bitcoinaddress

    # limit basic string and ints for now
    if not re.match("^[a-zA-Z0-9_-]+$", value):
        raise InvalidInput("Invalid value!")
    return value


def colordesc(colordesc):
    if not re.match("^(epobc|obc):[0-9a-f]+:[0-9]+:[0-9]+$", colordesc):
        raise InvalidInput("Invalid color description!")
    return colordesc


def jsonasset(data):
    data = json.loads(data)
    monikers = [moniker(m) for m in data['monikers']]
    color_set = [colordesc(cd) for cd in data['color_set']]
    _unit = unit(data['unit'])
    return { 'monikers' : monikers, 'color_set' : color_set, 'unit' : _unit }


def coloraddress(model, asset, coloraddress):

    # asset must match address asset id
    adm = model.get_asset_definition_manager()
    address_asset, btcaddress = adm.get_asset_and_address(coloraddress)
    if asset != address_asset:
        raise InvalidInput("Address and asset don't match!")

    # check if valid btcaddress
    if not model.validate_address(btcaddress):

        raise InvalidInput("Address not valid!")