INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Make a schema for a "standard" server response.
Standard server responses have 'status': True
and possibly 'indexing': True set. | def json_response_schema( expected_object_schema ):
"""
Make a schema for a "standard" server response.
Standard server responses have 'status': True
and possibly 'indexing': True set.
"""
schema = {
'type': 'object',
'properties': {
'status': {
'type'... |
Connect to the given "host:port" string
Returns a BlockstackRPCClient instance | def connect_hostport(hostport, timeout=RPC_DEFAULT_TIMEOUT, my_hostport=None):
"""
Connect to the given "host:port" string
Returns a BlockstackRPCClient instance
"""
host, port = url_to_host_port(hostport)
assert host is not None and port is not None
protocol = url_protocol(hostport)
i... |
rpc_ping
Returns {'alive': True} on succcess
Returns {'error': ...} on error | def ping(proxy=None, hostport=None):
"""
rpc_ping
Returns {'alive': True} on succcess
Returns {'error': ...} on error
"""
schema = {
'type': 'object',
'properties': {
'status': {
'type': 'string'
},
},
'required': [
... |
Get the atlas zonefile inventory from the given peer.
offset/count are in bytes.
Return {'status': True, 'inv': inventory} on success.
Return {'error': ...} on error | def get_zonefile_inventory(hostport, offset, count, timeout=30, my_hostport=None, proxy=None):
"""
Get the atlas zonefile inventory from the given peer.
offset/count are in bytes.
Return {'status': True, 'inv': inventory} on success.
Return {'error': ...} on error
"""
assert hostport or... |
Get an atlas peer's neighbors.
Return {'status': True, 'peers': [peers]} on success.
Return {'error': ...} on error | def get_atlas_peers(hostport, timeout=30, my_hostport=None, proxy=None):
"""
Get an atlas peer's neighbors.
Return {'status': True, 'peers': [peers]} on success.
Return {'error': ...} on error
"""
assert hostport or proxy, 'need either hostport or proxy'
peers_schema = {
'type': 'o... |
Get a set of zonefiles from the given server. Used primarily by Atlas.
Return {'status': True, 'zonefiles': {hash: data, ...}} on success
Return {'error': ...} on error | def get_zonefiles(hostport, zonefile_hashes, timeout=30, my_hostport=None, proxy=None):
"""
Get a set of zonefiles from the given server. Used primarily by Atlas.
Return {'status': True, 'zonefiles': {hash: data, ...}} on success
Return {'error': ...} on error
"""
assert hostport or proxy, 'ne... |
Push one or more zonefiles to the given server.
Each zone file in the list must be base64-encoded
Return {'status': True, 'saved': [...]} on success
Return {'error': ...} on error | def put_zonefiles(hostport, zonefile_data_list, timeout=30, my_hostport=None, proxy=None):
"""
Push one or more zonefiles to the given server.
Each zone file in the list must be base64-encoded
Return {'status': True, 'saved': [...]} on success
Return {'error': ...} on error
"""
assert hostp... |
Get zonefile information for zonefiles announced in [@from_block, @to_block]
Returns { 'last_block' : server's last seen block,
'zonefile_info' : [ { 'zonefile_hash' : '...',
'txid' : '...',
'block_height' : '...' } ] } | def get_zonefiles_by_block(from_block, to_block, hostport=None, proxy=None):
"""
Get zonefile information for zonefiles announced in [@from_block, @to_block]
Returns { 'last_block' : server's last seen block,
'zonefile_info' : [ { 'zonefile_hash' : '...',
't... |
Get the record for a name or a subdomain. Optionally include its history, and optionally return an expired name or a name in its grace period.
Return the blockchain-extracted information on success.
Return {'error': ...} on error
In particular, return {'error': 'Not found.'} if the name isn't registere... | def get_name_record(name, include_history=False, include_expired=False, include_grace=True, proxy=None, hostport=None,
history_page=None):
"""
Get the record for a name or a subdomain. Optionally include its history, and optionally return an expired name or a name in its grace period.
R... |
Get the blockchain record for a namespace.
Returns the dict on success
Returns {'error': ...} on failure | def get_namespace_record(namespace_id, proxy=None, hostport=None):
"""
Get the blockchain record for a namespace.
Returns the dict on success
Returns {'error': ...} on failure
"""
assert proxy or hostport, 'Need either proxy handle or hostport string'
if proxy is None:
proxy = conne... |
name_cost
Returns the name cost info on success
Returns {'amount': ..., 'units': ...} on success
Returns {'error': ...} on error | def get_name_cost(name, proxy=None, hostport=None):
"""
name_cost
Returns the name cost info on success
Returns {'amount': ..., 'units': ...} on success
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostpo... |
namespace_cost
Returns the namespace cost info on success.
Returns {'amount': ..., 'units': ...} on success (optionally with 'satoshis': ... if the namespace is priced in BTC)
Returns {'error': ...} on error | def get_namespace_cost(namespace_id, proxy=None, hostport=None):
"""
namespace_cost
Returns the namespace cost info on success.
Returns {'amount': ..., 'units': ...} on success (optionally with 'satoshis': ... if the namespace is priced in BTC)
Returns {'error': ...} on error
"""
assert prox... |
Get the types of tokens that an address owns
Returns a list of token types | def get_account_tokens(address, hostport=None, proxy=None):
"""
Get the types of tokens that an address owns
Returns a list of token types
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostport(hostport)
tokens_schema = {
'type': 'o... |
Get the balance of an account for a particular token
Returns an int | def get_account_balance(address, token_type, hostport=None, proxy=None):
"""
Get the balance of an account for a particular token
Returns an int
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostport(hostport)
balance_schema = {
'ty... |
Get a page of the account's history
Returns the list of account operations on success
Returns {'error': ...} on error | def get_account_history_page(address, page, hostport=None, proxy=None):
"""
Get a page of the account's history
Returns the list of account operations on success
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_h... |
get a page of all the names
Returns the list of names on success
Returns {'error': ...} on error | def get_all_names_page(offset, count, include_expired=False, hostport=None, proxy=None):
"""
get a page of all the names
Returns the list of names on success
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostp... |
Get the number of names, optionally counting the expired ones
Return {'error': ...} on failure | def get_num_names(include_expired=False, proxy=None, hostport=None):
"""
Get the number of names, optionally counting the expired ones
Return {'error': ...} on failure
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostport(hostport)
schema ... |
Get all subdomains within the given range.
Return the list of names on success
Return {'error': ...} on failure | def get_all_subdomains(offset=0, count=100, proxy=None, hostport=None):
"""
Get all subdomains within the given range.
Return the list of names on success
Return {'error': ...} on failure
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostpor... |
Get all names within the given range.
Return the list of names on success
Return {'error': ...} on failure | def get_all_names(offset=None, count=None, include_expired=False, proxy=None, hostport=None):
"""
Get all names within the given range.
Return the list of names on success
Return {'error': ...} on failure
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy ... |
Get all namespaces
Return the list of namespaces on success
Return {'error': ...} on failure
TODO: make this scale like get_all_names | def get_all_namespaces(offset=None, count=None, proxy=None, hostport=None):
"""
Get all namespaces
Return the list of namespaces on success
Return {'error': ...} on failure
TODO: make this scale like get_all_names
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
... |
Get a page of names in a namespace
Returns the list of names on success
Returns {'error': ...} on error | def get_names_in_namespace_page(namespace_id, offset, count, proxy=None, hostport=None):
"""
Get a page of names in a namespace
Returns the list of names on success
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connec... |
Get all names in a namespace
Returns the list of names on success
Returns {'error': ..} on error | def get_names_in_namespace(namespace_id, offset=None, count=None, proxy=None, hostport=None):
"""
Get all names in a namespace
Returns the list of names on success
Returns {'error': ..} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_... |
Get the names owned by an address.
Returns the list of names on success
Returns {'error': ...} on error | def get_names_owned_by_address(address, proxy=None, hostport=None):
"""
Get the names owned by an address.
Returns the list of names on success
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostport(hostport)
... |
Get the list of subdomain operations added by a txid
Returns the list of operations ([{...}]) on success
Returns {'error': ...} on failure | def get_subdomain_ops_at_txid(txid, proxy=None, hostport=None):
"""
Get the list of subdomain operations added by a txid
Returns the list of operations ([{...}]) on success
Returns {'error': ...} on failure
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
prox... |
Get the DID for a name or subdomain
Return the DID string on success
Return None if not found | def get_name_DID(name, proxy=None, hostport=None):
"""
Get the DID for a name or subdomain
Return the DID string on success
Return None if not found
"""
assert proxy or hostport, 'Need proxy or hostport'
if proxy is None:
proxy = connect_hostport(hostport)
did_schema = {
... |
Resolve a Blockstack decentralized identifier (DID) to its blockchain record.
Works for names and subdomains.
DID format: did:stack:v0:${address}-${name_index}, where:
* address is the address that created the name this DID references (version byte 0 or 5)
* name_index is the nth name ever created by t... | def get_DID_record(did, proxy=None, hostport=None):
"""
Resolve a Blockstack decentralized identifier (DID) to its blockchain record.
Works for names and subdomains.
DID format: did:stack:v0:${address}-${name_index}, where:
* address is the address that created the name this DID references (version... |
Get consensus at a block
Returns the consensus hash on success
Returns {'error': ...} on error | def get_consensus_at(block_height, proxy=None, hostport=None):
"""
Get consensus at a block
Returns the consensus hash on success
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need either proxy or hostport'
if proxy is None:
proxy = connect_hostport(hostport)
co... |
Get the *prior* states of the blockstack records that were
affected at the given block height.
Return the list of name records at the given height on success.
Return {'error': ...} on error. | def get_blockstack_transactions_at(block_id, proxy=None, hostport=None):
"""
Get the *prior* states of the blockstack records that were
affected at the given block height.
Return the list of name records at the given height on success.
Return {'error': ...} on error.
"""
assert proxy or host... |
Get consensus hashes for a list of blocks
NOTE: returns {block_height (int): consensus_hash (str)}
(coerces the key to an int)
Returns {'error': ...} on error | def get_consensus_hashes(block_heights, hostport=None, proxy=None):
"""
Get consensus hashes for a list of blocks
NOTE: returns {block_height (int): consensus_hash (str)}
(coerces the key to an int)
Returns {'error': ...} on error
"""
assert proxy or hostport, 'Need proxy or hostport'
if... |
Get a block height from a consensus hash
Returns the block height on success
Returns {'error': ...} on failure | def get_block_from_consensus(consensus_hash, hostport=None, proxy=None):
"""
Get a block height from a consensus hash
Returns the block height on success
Returns {'error': ...} on failure
"""
assert hostport or proxy, 'Need hostport or proxy'
if proxy is None:
proxy = connect_hostpor... |
Get a page of the name's history
Returns {'status': True, 'history': ..., 'indexing': ..., 'lastblock': ...} on success
Returns {'error': ...} on error | def get_name_history_page(name, page, hostport=None, proxy=None):
"""
Get a page of the name's history
Returns {'status': True, 'history': ..., 'indexing': ..., 'lastblock': ...} on success
Returns {'error': ...} on error
"""
assert hostport or proxy, 'Need hostport or proxy'
if proxy is Non... |
Given two name histories (grouped by block), merge them. | def name_history_merge(h1, h2):
"""
Given two name histories (grouped by block), merge them.
"""
ret = {}
blocks_1 = [int(b) for b in h1.keys()]
blocks_2 = [int(b) for b in h2.keys()]
# find overlapping blocks
overlap = list(set(blocks_1).intersection(set(blocks_2)))
if len(overlap)... |
Get the full history of a name
Returns {'status': True, 'history': ...} on success, where history is grouped by block
Returns {'error': ...} on error | def get_name_history(name, hostport=None, proxy=None, history_page=None):
"""
Get the full history of a name
Returns {'status': True, 'history': ...} on success, where history is grouped by block
Returns {'error': ...} on error
"""
assert hostport or proxy, 'Need hostport or proxy'
if proxy ... |
Get the current name record and its history
(this is a replacement for proxy.get_name_blockchain_record())
Return {'status': True, 'record': ...} on success, where .record.history is defined as {block_height: [{history}, {history}, ...], ...}
Return {'error': ...} on error | def get_name_and_history(name, include_expired=False, include_grace=True, hostport=None, proxy=None, history_page=None):
"""
Get the current name record and its history
(this is a replacement for proxy.get_name_blockchain_record())
Return {'status': True, 'record': ...} on success, where .record.history... |
Get the name as it was at a particular height.
Returns the name record states at this block height on success (an array)
Returns {'error': ...} on error | def get_name_at(name, block_id, include_expired=False, hostport=None, proxy=None):
"""
Get the name as it was at a particular height.
Returns the name record states at this block height on success (an array)
Returns {'error': ...} on error
"""
assert hostport or proxy, 'Need hostport or proxy'
... |
Determine if a name set a given zone file hash.
Return {'result': True/False} if so
Return {'error': ...} on error | def is_name_zonefile_hash(name, zonefile_hash, hostport=None, proxy=None):
"""
Determine if a name set a given zone file hash.
Return {'result': True/False} if so
Return {'error': ...} on error
"""
assert hostport or proxy, 'Need hostport or proxy'
if proxy is None:
proxy = connect_h... |
Given a URL, fetch and decode the JWT it points to.
If address is given, then authenticate the JWT with the address.
Return None if we could not fetch it, or unable to authenticate it.
NOTE: the URL must be usable by the requests library | def get_JWT(url, address=None):
"""
Given a URL, fetch and decode the JWT it points to.
If address is given, then authenticate the JWT with the address.
Return None if we could not fetch it, or unable to authenticate it.
NOTE: the URL must be usable by the requests library
"""
jwt_txt = No... |
Resolve a name to its profile.
This is a multi-step process:
1. get the name record
2. get the zone file
3. parse the zone file to get its URLs (if it's not well-formed, then abort)
4. fetch and authenticate the JWT at each URL (abort if there are none)
5. extract the profile JSON and return tha... | def resolve_profile(name, include_expired=False, include_name_record=False, hostport=None, proxy=None):
"""
Resolve a name to its profile.
This is a multi-step process:
1. get the name record
2. get the zone file
3. parse the zone file to get its URLs (if it's not well-formed, then abort)
4.... |
Resolve a DID to a public key.
This is a multi-step process:
1. get the name record
2. get the zone file
3. parse the zone file to get its URLs (if it's not well-formed, then abort)
4. fetch and authenticate the JWT at each URL (abort if there are none)
5. extract the public key from the JWT and... | def resolve_DID(did, hostport=None, proxy=None):
"""
Resolve a DID to a public key.
This is a multi-step process:
1. get the name record
2. get the zone file
3. parse the zone file to get its URLs (if it's not well-formed, then abort)
4. fetch and authenticate the JWT at each URL (abort if t... |
Decode a zone file for a name.
Must be either a well-formed DNS zone file, or a legacy Onename profile.
Return None on error | def decode_name_zonefile(name, zonefile_txt):
"""
Decode a zone file for a name.
Must be either a well-formed DNS zone file, or a legacy Onename profile.
Return None on error
"""
user_zonefile = None
try:
# by default, it's a zonefile-formatted text file
user_zonefile_defaul... |
Used for testing only! | def format_unspents(unspents):
"""
Used for testing only!
"""
assert BLOCKSTACK_TEST, 'format_unspents can only be used in test mode!'
return [{
"transaction_hash": s["txid"],
"outpoint": {
'hash': s['txid'],
'index': s["vout"],
},
"value": int... |
Used for testing only!
Get the spendable transaction outputs, also known as UTXOs or
unspent transaction outputs.
NOTE: this will only return unspents if the address provided is present
in the bitcoind server. | def get_unspents(address, bitcoind):
"""
Used for testing only!
Get the spendable transaction outputs, also known as UTXOs or
unspent transaction outputs.
NOTE: this will only return unspents if the address provided is present
in the bitcoind server.
"""
assert BLOCKSTACK_TEST, 'get_un... |
Generate and reply headers | def _send_headers(self, status_code=200, content_type='application/json', more_headers={}):
"""
Generate and reply headers
"""
self.send_response(status_code)
self.send_header('content-type', content_type)
self.send_header('Access-Control-Allow-Origin', '*') # CORS
... |
Read raw uploaded data.
Return the data on success
Return None on I/O error, or if maxlen is not None and the number of bytes read is too big | def _read_payload(self, maxlen=None):
"""
Read raw uploaded data.
Return the data on success
Return None on I/O error, or if maxlen is not None and the number of bytes read is too big
"""
client_address_str = "{}:{}".format(self.client_address[0], self.client_address[1])... |
Return a JSON-serializable data structure | def _reply_json(self, json_payload, status_code=200):
"""
Return a JSON-serializable data structure
"""
self._send_headers(status_code=status_code)
json_str = json.dumps(json_payload)
self.wfile.write(json_str) |
Read a JSON payload from the requester
Return the parsed payload on success
Return None on error | def _read_json(self, schema=None, maxlen=JSONRPC_MAX_SIZE):
"""
Read a JSON payload from the requester
Return the parsed payload on success
Return None on error
"""
# JSON post?
request_type = self.headers.get('content-type', None)
client_address_str = "{}... |
Parse query string, but enforce one instance of each variable.
Return a dict with the variables on success
Return None on parse error | def parse_qs(self, qs):
"""
Parse query string, but enforce one instance of each variable.
Return a dict with the variables on success
Return None on parse error
"""
qs_state = urllib2.urlparse.parse_qs(qs)
ret = {}
for qs_var, qs_value_list in qs_state.it... |
Parse and obtain the path and query values.
We don't care about fragments.
Return {'path': ..., 'qs_values': ...} on success
Return {'error': ...} on error | def get_path_and_qs(self):
"""
Parse and obtain the path and query values.
We don't care about fragments.
Return {'path': ..., 'qs_values': ...} on success
Return {'error': ...} on error
"""
path_parts = self.path.split("?", 1)
if len(path_parts) > 1:
... |
Look up the method to call
Return the route info and its arguments on success:
Return None on error | def _route_match( self, method_name, path_info, route_table ):
"""
Look up the method to call
Return the route info and its arguments on success:
Return None on error
"""
path = path_info['path']
for route_path, route_info in route_table.items():
if m... |
Give back CORS preflight check headers | def OPTIONS_preflight( self, path_info ):
"""
Give back CORS preflight check headers
"""
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*') # CORS
self.send_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE')
self.send_hea... |
Get all names owned by an address
Returns the list on success
Return 404 on unsupported blockchain
Return 502 on failure to get names for any non-specified reason | def GET_names_owned_by_address( self, path_info, blockchain, address ):
"""
Get all names owned by an address
Returns the list on success
Return 404 on unsupported blockchain
Return 502 on failure to get names for any non-specified reason
"""
if not check_address(... |
Get all token types that an address owns
Returns {'tokens': [...]} | def GET_account_tokens(self, path_info, account_addr):
"""
Get all token types that an address owns
Returns {'tokens': [...]}
"""
if not check_account_address(account_addr):
return self._reply_json({'error': 'Invalid address'}, status_code=400)
blockstackd_ur... |
Get the state of a particular token account
Returns the account | def GET_account_record(self, path_info, account_addr, token_type):
"""
Get the state of a particular token account
Returns the account
"""
if not check_account_address(account_addr):
return self._reply_json({'error': 'Invalid address'}, status_code=400)
if no... |
Get the balance of a particular token
Returns {'balance': ...} | def GET_account_balance(self, path_info, account_addr, token_type):
"""
Get the balance of a particular token
Returns {'balance': ...}
"""
if not check_account_address(account_addr):
return self._reply_json({'error': 'Invalid address'}, status_code=400)
if no... |
Get the history of an account at a given page.
Returns [{...}] | def GET_account_history(self, path_info, account_addr):
"""
Get the history of an account at a given page.
Returns [{...}]
"""
if not check_account_address(account_addr):
return self._reply_json({'error': 'Invalid address'}, status_code=400)
qs_values = path_... |
Get the state(s) of an account at a particular point in history
Returns [{...}] | def GET_account_at(self, path_info, account_addr, block_height):
"""
Get the state(s) of an account at a particular point in history
Returns [{...}]
"""
if not check_account_address(account_addr):
return self._reply_json({'error': 'Invalid address'}, status_code=400)
... |
Get all names in existence
If `all=true` is set, then include expired names.
Returns the list on success
Returns 400 on invalid arguments
Returns 502 on failure to get names | def GET_names( self, path_info ):
"""
Get all names in existence
If `all=true` is set, then include expired names.
Returns the list on success
Returns 400 on invalid arguments
Returns 502 on failure to get names
"""
include_expired = False
qs_val... |
Get all subdomains in existence.
Requires page={int}
Returns the list on success
Returns 400 on invalid arguments
Returns 502 on failure to get names | def GET_subdomains( self, path_info ):
"""
Get all subdomains in existence.
Requires page={int}
Returns the list on success
Returns 400 on invalid arguments
Returns 502 on failure to get names
"""
qs_values = path_info['qs_values']
page = qs_values... |
Get all subdomain operations processed in a given transaction.
Returns the list of subdomains on success (can be empty)
Returns 502 on failure to get subdomains | def GET_subdomain_ops(self, path_info, txid):
"""
Get all subdomain operations processed in a given transaction.
Returns the list of subdomains on success (can be empty)
Returns 502 on failure to get subdomains
"""
blockstackd_url = get_blockstackd_url()
subdomain... |
Look up a name's zonefile, address, and last TXID
Reply status, zonefile, zonefile hash, address, and last TXID.
'status' can be 'available', 'registered', 'revoked', or 'pending' | def GET_name_info( self, path_info, name ):
"""
Look up a name's zonefile, address, and last TXID
Reply status, zonefile, zonefile hash, address, and last TXID.
'status' can be 'available', 'registered', 'revoked', or 'pending'
"""
if not check_name(name) and not check_su... |
Get the history of a name or subdomain.
Requires 'page' in the query string
return the history on success
return 400 on invalid start_block or end_block
return 502 on failure to query blockstack server | def GET_name_history(self, path_info, name):
"""
Get the history of a name or subdomain.
Requires 'page' in the query string
return the history on success
return 400 on invalid start_block or end_block
return 502 on failure to query blockstack server
"""
i... |
Get the name's current zonefile data.
With `raw=1` on the query string, return the raw zone file.
Otherwise, return the (raw) zone file only if it
is well-formed (and return it in a JSON dict).
Reply the {'zonefile': zonefile} on success
Reply the raw zone file as application/oc... | def GET_name_zonefile( self, path_info, name ):
"""
Get the name's current zonefile data.
With `raw=1` on the query string, return the raw zone file.
Otherwise, return the (raw) zone file only if it
is well-formed (and return it in a JSON dict).
Reply the {'zonefile': zo... |
Get a raw zonefile
Reply the zonefile as application/octet-stream
Reply 404 if not found | def GET_zonefile(self, path_info, zonefile_hash):
"""
Get a raw zonefile
Reply the zonefile as application/octet-stream
Reply 404 if not found
"""
if not check_string(zonefile_hash, pattern=OP_ZONEFILE_HASH_PATTERN):
return self._reply_json({'error': 'Invalid ... |
Publish a zonefile which has *already* been announced.
Return 200 and {'status': True, 'servers': [...]} on success
Return 400 on invalid request, such as invalid JSON, JSON that doesn't match the schema, etc.
Return 502 on failure to replicate the zone file | def POST_zonefile(self, path_info):
"""
Publish a zonefile which has *already* been announced.
Return 200 and {'status': True, 'servers': [...]} on success
Return 400 on invalid request, such as invalid JSON, JSON that doesn't match the schema, etc.
Return 502 on failure to repli... |
Get a historic zonefile for a name
With `raw=1` on the query string, return the raw zone file
Reply 200 with {'zonefile': zonefile} on success
Reply 204 with {'error': ...} if the zone file is non-standard
Reply 404 on not found
Reply 502 on failure to fetch data | def GET_name_zonefile_by_hash( self, path_info, name, zonefile_hash ):
"""
Get a historic zonefile for a name
With `raw=1` on the query string, return the raw zone file
Reply 200 with {'zonefile': zonefile} on success
Reply 204 with {'error': ...} if the zone file is non-standar... |
Get a user profile.
Reply the profile on success
Return 404 on failure to load | def GET_did(self, path_info, did):
"""
Get a user profile.
Reply the profile on success
Return 404 on failure to load
"""
try:
did_info = parse_DID(did)
assert did_info['name_type'] in ('name', 'subdomain')
except Exception as e:
... |
Get a user profile.
Reply the profile on success
Return 404 on failure to load | def GET_user_profile( self, path_info, user_id ):
"""
Get a user profile.
Reply the profile on success
Return 404 on failure to load
"""
if not check_name(user_id) and not check_subdomain(user_id):
return self._reply_json({'error': 'Invalid name or subdomain'}... |
Get the price for a namespace
Reply the price for the namespace as {'units': "...", 'amount': "..."}
Reply 502 if we can't reach the namespace for whatever reason | def GET_prices_namespace( self, path_info, namespace_id ):
"""
Get the price for a namespace
Reply the price for the namespace as {'units': "...", 'amount': "..."}
Reply 502 if we can't reach the namespace for whatever reason
"""
if not check_namespace(namespace_id):
... |
Get the price for a name in a namespace
Reply the price as {'name_price': {'amount': str(...), 'units': str(...)}} (also, 'satoshis': ... if the name is in BT)
Reply 404 if the namespace doesn't exist
Reply 502 if we can't reach the server for whatever reason | def GET_prices_name( self, path_info, name ):
"""
Get the price for a name in a namespace
Reply the price as {'name_price': {'amount': str(...), 'units': str(...)}} (also, 'satoshis': ... if the name is in BT)
Reply 404 if the namespace doesn't exist
Reply 502 if we can't reach t... |
Get the list of all namespaces
Reply all existing namespaces
Reply 502 if we can't reach the server for whatever reason | def GET_namespaces( self, path_info ):
"""
Get the list of all namespaces
Reply all existing namespaces
Reply 502 if we can't reach the server for whatever reason
"""
qs_values = path_info['qs_values']
offset = qs_values.get('offset', None)
count = qs_valu... |
Look up a namespace's info
Reply information about a namespace
Reply 404 if the namespace doesn't exist
Reply 502 for any error in talking to the blocksatck server | def GET_namespace_info( self, path_info, namespace_id ):
"""
Look up a namespace's info
Reply information about a namespace
Reply 404 if the namespace doesn't exist
Reply 502 for any error in talking to the blocksatck server
"""
if not check_namespace(namespace_id... |
Get the number of names in a namespace
Reply the number on success
Reply 404 if the namespace does not exist
Reply 502 on failure to talk to the blockstack server | def GET_namespace_num_names(self, path_info, namespace_id):
"""
Get the number of names in a namespace
Reply the number on success
Reply 404 if the namespace does not exist
Reply 502 on failure to talk to the blockstack server
"""
if not check_namespace(namespace_... |
Get the list of names in a namespace
Reply the list of names in a namespace
Reply 404 if the namespace doesn't exist
Reply 502 for any error in talking to the blockstack server | def GET_namespace_names( self, path_info, namespace_id ):
"""
Get the list of names in a namespace
Reply the list of names in a namespace
Reply 404 if the namespace doesn't exist
Reply 502 for any error in talking to the blockstack server
"""
if not check_namespac... |
Get the name's historic name operations
Reply the list of nameops at the given block height
Reply 404 for blockchains other than those supported
Reply 502 for any error we have in talking to the blockstack server | def GET_blockchain_ops( self, path_info, blockchain_name, blockheight ):
"""
Get the name's historic name operations
Reply the list of nameops at the given block height
Reply 404 for blockchains other than those supported
Reply 502 for any error we have in talking to the blocksta... |
Get the name's blockchain record in full
Reply the raw blockchain record on success
Reply 404 if the name is not found
Reply 502 if we have an error talking to the server | def GET_blockchain_name_record( self, path_info, blockchain_name, name ):
"""
Get the name's blockchain record in full
Reply the raw blockchain record on success
Reply 404 if the name is not found
Reply 502 if we have an error talking to the server
"""
if not chec... |
Handle GET /blockchains/:blockchainID/name_count
Takes `all=true` to include expired names
Reply with the number of names on this blockchain | def GET_blockchain_num_names( self, path_info, blockchain_name ):
"""
Handle GET /blockchains/:blockchainID/name_count
Takes `all=true` to include expired names
Reply with the number of names on this blockchain
"""
if blockchain_name != 'bitcoin':
# not suppor... |
Handle GET /blockchains/:blockchainID/subdomains_count
Takes `all=true` to include expired names
Reply with the number of names on this blockchain | def GET_blockchain_num_subdomains( self, path_info, blockchain_name ):
"""
Handle GET /blockchains/:blockchainID/subdomains_count
Takes `all=true` to include expired names
Reply with the number of names on this blockchain
"""
if blockchain_name != 'bitcoin':
#... |
Works only in test mode!
Get the confirmed balance for an address | def _get_balance( self, get_address, min_confs ):
"""
Works only in test mode!
Get the confirmed balance for an address
"""
bitcoind_opts = get_bitcoin_opts()
bitcoind_host = bitcoind_opts['bitcoind_server']
bitcoind_port = bitcoind_opts['bitcoind_port']
b... |
Works only in test mode!
Handle GET /insight-api/addr/:address/balance | def GET_confirmed_balance_insight( self, path_info, address ):
"""
Works only in test mode!
Handle GET /insight-api/addr/:address/balance
"""
if not BLOCKSTACK_TEST:
return self._send_headers(status_code=404, content_type='text/plain')
if not check_address(ad... |
Handle GET /insight-api/addr/:address/utxo
NOTE: this is not compatible with the Bitcore Insight API method of the same name | def GET_utxos_insight( self, path_info, address ):
"""
Handle GET /insight-api/addr/:address/utxo
NOTE: this is not compatible with the Bitcore Insight API method of the same name
"""
if not BLOCKSTACK_TEST:
return self._send_headers(status_code=404, content_type='tex... |
getinfo | def GET_getinfo(self, path_info):
"""
getinfo
"""
blockstackd_url = get_blockstackd_url()
info = blockstackd_client.getinfo(hostport=blockstackd_url)
if json_is_error(info):
# error
status_code = info.get('http_status', 502)
return self... |
Bind to our port | def bind(self):
"""
Bind to our port
"""
log.debug("Set SO_REUSADDR")
self.socket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
# we want daemon threads, so we join on abrupt shutdown (applies if multithreaded)
self.daemon_threads = True
... |
Top-level dispatch method | def _dispatch(self, method_name):
"""
Top-level dispatch method
"""
URLENCODING_CLASS = r'[a-zA-Z0-9\-_.~%]'
routes = {
r'^/v1/ping$': {
'routes': {
'GET': self.GET_ping,
},
},
r'^/v1/info$':... |
Deflect if we have too many inbound requests | def overloaded(self, client_addr):
"""
Deflect if we have too many inbound requests
"""
overloaded_txt = 'HTTP/1.0 429 Too Many Requests\r\nServer: BaseHTTP/0.3 Python/2.7.14+\r\nContent-type: text/plain\r\nContent-length: 17\r\n\r\nToo many requests'
if BLOCKSTACK_TEST:
... |
Make sure that a string is a byte string
:arg obj: An object to make sure is a byte string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used as a traceback-free
version of ``str(obj)``.
:kwarg encoding: The en... | def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
"""Make sure that a string is a byte string
:arg obj: An object to make sure is a byte string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used... |
Make sure that a string is a text string
:arg obj: An object to make sure is a text string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used as a traceback-free
version of ``str(obj)``.
:kwarg encoding: The en... | def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
"""Make sure that a string is a text string
:arg obj: An object to make sure is a text string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used ... |
Push images to a registry. Requires authenticating with the registry prior to starting
the push. If your engine's config file does not already contain an authorization for the
registry, pass username and/or password. If you exclude password, you will be prompted. | def hostcmd_push(base_path, project_name, engine_name, vars_files=None, config_file=None, **kwargs):
"""
Push images to a registry. Requires authenticating with the registry prior to starting
the push. If your engine's config file does not already contain an authorization for the
registry, pass username... |
Pushes images to a Docker registry. Returns dict containing attributes used to push images. | def push_images(base_path, image_namespace, engine_obj, config, **kwargs):
""" Pushes images to a Docker registry. Returns dict containing attributes used to push images. """
config_path = kwargs.get('config_path', engine_obj.auth_config_path)
username = kwargs.get('username')
password = kwargs.get('pas... |
Remove a container for an existing service. Handy for removing an existing conductor. | def remove_existing_container(engine_obj, service_name, remove_volumes=False):
"""
Remove a container for an existing service. Handy for removing an existing conductor.
"""
conductor_container_id = engine_obj.get_container_id_for_service(service_name)
if engine_obj.service_is_running(service_name):
... |
Given a push-to value, return the registry and namespace.
:param push_to: string: User supplied --push-to value.
:param default_url: string: Container engine's default_index value (e.g. docker.io).
:return: tuple: registry_url, namespace | def resolve_push_to(push_to, default_url, default_namespace):
'''
Given a push-to value, return the registry and namespace.
:param push_to: string: User supplied --push-to value.
:param default_url: string: Container engine's default_index value (e.g. docker.io).
:return: tuple: registry_url, names... |
Starting with the path, recursively set ownership of files and subdirectories.
:param path: Root path
:param uid: User ID
:param gid: Group ID
:return: None | def set_path_ownership(path, uid, gid):
"""
Starting with the path, recursively set ownership of files and subdirectories.
:param path: Root path
:param uid: User ID
:param gid: Group ID
:return: None
"""
os.chown(path, uid, gid)
for root, dirs, files in os.walk(path):
for d ... |
Push images to a registry | def conductorcmd_push(engine_name, project_name, services, **kwargs):
""" Push images to a registry """
username = kwargs.pop('username')
password = kwargs.pop('password')
email = kwargs.pop('email')
url = kwargs.pop('url')
namespace = kwargs.pop('namespace')
tag = kwargs.pop('tag')
conf... |
Generate Openshift route templates or playbook tasks. Each port on a service definition found in container.yml
represents an externally exposed port. | def get_route_templates(self):
"""
Generate Openshift route templates or playbook tasks. Each port on a service definition found in container.yml
represents an externally exposed port.
"""
def _get_published_ports(service_config):
result = []
for port in s... |
Wait for a container to have a State.Running value = true.
:param hosts: list of service names taken from container.yml
:param max_attempts: Max number of times to inspect the container and check State.Running
:param sleep_time: Number of seconds to wait between attempts.
:return: dict of host:running p... | def wait_on_hosts(hosts, max_attempts=3, sleep_time=1):
'''
Wait for a container to have a State.Running value = true.
:param hosts: list of service names taken from container.yml
:param max_attempts: Max number of times to inspect the container and check State.Running
:param sleep_time: Number of s... |
Returns contents of the Dockerfile as an array, where each line in the file is an element in the array.
:return: list | def lines_iter(self):
'''
Returns contents of the Dockerfile as an array, where each line in the file is an element in the array.
:return: list
'''
# Convert unicode chars to string
byte_to_string = lambda x: x.strip().decode(u'utf-8') if isinstance(x, bytes) else x.strip... |
Comments can be anywhere. So break apart the Dockerfile into significant
lines and any comments that precede them. And if a line is a carryover
from the previous via an escaped-newline, bring the directive with it. | def preparse_iter(self):
"""
Comments can be anywhere. So break apart the Dockerfile into significant
lines and any comments that precede them. And if a line is a carryover
from the previous via an escaped-newline, bring the directive with it.
"""
to_yield = {}
la... |
Create roles/dockerfile-to-ansible path and role structure.
:return: None | def create_role_from_template(self):
'''
Create roles/dockerfile-to-ansible path and role structure.
:return: None
'''
description = u"Imported Dockerfile for {}".format(self.project_name)
create_role_from_templates(role_name=os.path.basename(self.import_from),
... |
Run a particular container. The kwargs argument contains individual
parameter overrides from the service definition. | def run_container(self, image_id, service_name, **kwargs):
"""Run a particular container. The kwargs argument contains individual
parameter overrides from the service definition."""
run_kwargs = self.run_kwargs_for_service(service_name)
run_kwargs.update(kwargs, relax=True)
logge... |
Convert the top-level 'secrets' directive to the Docker format
:return: secrets dict | def _get_top_level_secrets(self):
"""
Convert the top-level 'secrets' directive to the Docker format
:return: secrets dict
"""
top_level_secrets = dict()
if self.secrets:
for secret, secret_definition in iteritems(self.secrets):
if isinstance(s... |
Generate an Ansible playbook to orchestrate services.
:param url: registry URL where images will be pulled from
:param namespace: registry namespace
:return: playbook dict | def generate_orchestration_playbook(self, url=None, namespace=None, vault_files=None, **kwargs):
"""
Generate an Ansible playbook to orchestrate services.
:param url: registry URL where images will be pulled from
:param namespace: registry namespace
:return: playbook dict
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.