bigchaindb/bigchaindb/web/views/parameters.py
Troy McConaghy abdd23f5a6 Problem: Source files contain no license info (#2455)
* Problem: Source files contain no license info

Solution: Add comments with SPDX license info to source files

* Python 3 files don't need # -*- coding: utf-8 -*-
2018-08-16 12:31:32 +02:00

47 lines
1.1 KiB
Python

# Copyright BigchainDB GmbH and BigchainDB contributors
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
import re
def valid_txid(txid):
if re.match('^[a-fA-F0-9]{64}$', txid):
return txid.lower()
raise ValueError('Invalid hash')
def valid_bool(val):
val = val.lower()
if val == 'true':
return True
if val == 'false':
return False
raise ValueError('Boolean value must be "true" or "false" (lowercase)')
def valid_ed25519(key):
if (re.match('^[1-9a-zA-Z]{43,44}$', key) and not
re.match('.*[Il0O]', key)):
return key
raise ValueError('Invalid base58 ed25519 key')
def valid_operation(op):
op = op.upper()
if op == 'CREATE':
return 'CREATE'
if op == 'TRANSFER':
return 'TRANSFER'
raise ValueError('Operation must be "CREATE" or "TRANSFER"')
def valid_mode(mode):
if mode == 'async':
return 'broadcast_tx_async'
if mode == 'sync':
return 'broadcast_tx_sync'
if mode == 'commit':
return 'broadcast_tx_commit'
raise ValueError('Mode must be "async", "sync" or "commit"')