mirror of
https://github.com/planetmint/planetmint.git
synced 2025-06-07 14:46:38 +00:00
Merge pull request #81 from LaurentDeMontBlanc/update-transaction-schema-to-v3
Update transaction schema to v3
This commit is contained in:
commit
06085e3798
@ -17,31 +17,32 @@ from planetmint.transactions.common.exceptions import SchemaValidationError
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _load_schema(name, path=__file__):
|
def _load_schema(name, version, path=__file__):
|
||||||
"""Load a schema from disk"""
|
"""Load a schema from disk"""
|
||||||
path = os.path.join(os.path.dirname(path), name + '.yaml')
|
path = os.path.join(os.path.dirname(path), version, name + '.yaml')
|
||||||
with open(path) as handle:
|
with open(path) as handle:
|
||||||
schema = yaml.safe_load(handle)
|
schema = yaml.safe_load(handle)
|
||||||
fast_schema = rapidjson.Validator(rapidjson.dumps(schema))
|
fast_schema = rapidjson.Validator(rapidjson.dumps(schema))
|
||||||
return path, (schema, fast_schema)
|
return path, (schema, fast_schema)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: make this an env var from a config file
|
||||||
TX_SCHEMA_VERSION = 'v2.0'
|
TX_SCHEMA_VERSION = 'v2.0'
|
||||||
|
|
||||||
TX_SCHEMA_PATH, TX_SCHEMA_COMMON = _load_schema('transaction_' +
|
TX_SCHEMA_PATH, TX_SCHEMA_COMMON = _load_schema('transaction',
|
||||||
TX_SCHEMA_VERSION)
|
TX_SCHEMA_VERSION)
|
||||||
_, TX_SCHEMA_CREATE = _load_schema('transaction_create_' +
|
_, TX_SCHEMA_CREATE = _load_schema('transaction_create',
|
||||||
TX_SCHEMA_VERSION)
|
TX_SCHEMA_VERSION)
|
||||||
_, TX_SCHEMA_TRANSFER = _load_schema('transaction_transfer_' +
|
_, TX_SCHEMA_TRANSFER = _load_schema('transaction_transfer',
|
||||||
TX_SCHEMA_VERSION)
|
TX_SCHEMA_VERSION)
|
||||||
|
|
||||||
_, TX_SCHEMA_VALIDATOR_ELECTION = _load_schema('transaction_validator_election_' +
|
_, TX_SCHEMA_VALIDATOR_ELECTION = _load_schema('transaction_validator_election',
|
||||||
TX_SCHEMA_VERSION)
|
TX_SCHEMA_VERSION)
|
||||||
|
|
||||||
_, TX_SCHEMA_CHAIN_MIGRATION_ELECTION = _load_schema('transaction_chain_migration_election_' +
|
_, TX_SCHEMA_CHAIN_MIGRATION_ELECTION = _load_schema('transaction_chain_migration_election',
|
||||||
TX_SCHEMA_VERSION)
|
TX_SCHEMA_VERSION)
|
||||||
|
|
||||||
_, TX_SCHEMA_VOTE = _load_schema('transaction_vote_' + TX_SCHEMA_VERSION)
|
_, TX_SCHEMA_VOTE = _load_schema('transaction_vote', TX_SCHEMA_VERSION)
|
||||||
|
|
||||||
|
|
||||||
def _validate_schema(schema, body):
|
def _validate_schema(schema, body):
|
||||||
|
174
planetmint/transactions/common/schema/v3.0/transaction.yaml
Normal file
174
planetmint/transactions/common/schema/v3.0/transaction.yaml
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
|
# Planetmint and IPDB software contributors.
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
---
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
title: Transaction Schema
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- inputs
|
||||||
|
- outputs
|
||||||
|
- operation
|
||||||
|
- metadata
|
||||||
|
- assets
|
||||||
|
- version
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
anyOf:
|
||||||
|
- "$ref": "#/definitions/sha3_hexdigest"
|
||||||
|
- type: 'null'
|
||||||
|
operation:
|
||||||
|
"$ref": "#/definitions/operation"
|
||||||
|
assets:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/asset"
|
||||||
|
inputs:
|
||||||
|
type: array
|
||||||
|
title: "Transaction inputs"
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/input"
|
||||||
|
outputs:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/output"
|
||||||
|
metadata:
|
||||||
|
"$ref": "#/definitions/metadata"
|
||||||
|
version:
|
||||||
|
type: string
|
||||||
|
pattern: "^2\\.0$"
|
||||||
|
definitions:
|
||||||
|
offset:
|
||||||
|
type: integer
|
||||||
|
minimum: 0
|
||||||
|
base58:
|
||||||
|
pattern: "[1-9a-zA-Z^OIl]{43,44}"
|
||||||
|
type: string
|
||||||
|
public_keys:
|
||||||
|
anyOf:
|
||||||
|
- type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/base58"
|
||||||
|
- type: 'null'
|
||||||
|
sha3_hexdigest:
|
||||||
|
pattern: "[0-9a-f]{64}"
|
||||||
|
type: string
|
||||||
|
uuid4:
|
||||||
|
pattern: "[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}"
|
||||||
|
type: string
|
||||||
|
operation:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- CREATE
|
||||||
|
- TRANSFER
|
||||||
|
- VALIDATOR_ELECTION
|
||||||
|
- CHAIN_MIGRATION_ELECTION
|
||||||
|
- VOTE
|
||||||
|
- COMPOSE
|
||||||
|
- DECOMPOSE
|
||||||
|
asset:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
"$ref": "#/definitions/sha3_hexdigest"
|
||||||
|
data:
|
||||||
|
anyOf:
|
||||||
|
- type: object
|
||||||
|
additionalProperties: true
|
||||||
|
- type: 'null'
|
||||||
|
output:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- amount
|
||||||
|
- condition
|
||||||
|
- public_keys
|
||||||
|
properties:
|
||||||
|
amount:
|
||||||
|
type: string
|
||||||
|
pattern: "^[0-9]{1,20}$"
|
||||||
|
condition:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- details
|
||||||
|
- uri
|
||||||
|
properties:
|
||||||
|
details:
|
||||||
|
"$ref": "#/definitions/condition_details"
|
||||||
|
uri:
|
||||||
|
type: string
|
||||||
|
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})[?]\
|
||||||
|
(fpt=(ed25519|threshold)-sha-256(&)?|cost=[0-9]+(&)?|\
|
||||||
|
subtypes=ed25519-sha-256(&)?){2,3}$"
|
||||||
|
public_keys:
|
||||||
|
"$ref": "#/definitions/public_keys"
|
||||||
|
input:
|
||||||
|
type: "object"
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- owners_before
|
||||||
|
- fulfillment
|
||||||
|
properties:
|
||||||
|
owners_before:
|
||||||
|
"$ref": "#/definitions/public_keys"
|
||||||
|
fulfillment:
|
||||||
|
anyOf:
|
||||||
|
- type: string
|
||||||
|
pattern: "^[a-zA-Z0-9_-]*$"
|
||||||
|
- "$ref": "#/definitions/condition_details"
|
||||||
|
fulfills:
|
||||||
|
anyOf:
|
||||||
|
- type: 'object'
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- output_index
|
||||||
|
- transaction_id
|
||||||
|
properties:
|
||||||
|
output_index:
|
||||||
|
"$ref": "#/definitions/offset"
|
||||||
|
transaction_id:
|
||||||
|
"$ref": "#/definitions/sha3_hexdigest"
|
||||||
|
- type: 'null'
|
||||||
|
metadata:
|
||||||
|
anyOf:
|
||||||
|
- type: object
|
||||||
|
additionalProperties: true
|
||||||
|
minProperties: 1
|
||||||
|
- type: 'null'
|
||||||
|
condition_details:
|
||||||
|
anyOf:
|
||||||
|
- type: object
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
- public_key
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
pattern: "^ed25519-sha-256$"
|
||||||
|
public_key:
|
||||||
|
"$ref": "#/definitions/base58"
|
||||||
|
- type: object
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- type
|
||||||
|
- threshold
|
||||||
|
- subconditions
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
type: "string"
|
||||||
|
pattern: "^threshold-sha-256$"
|
||||||
|
threshold:
|
||||||
|
type: integer
|
||||||
|
minimum: 1
|
||||||
|
maximum: 100
|
||||||
|
subconditions:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/condition_details"
|
@ -0,0 +1,51 @@
|
|||||||
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
|
# Planetmint and IPDB software contributors.
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
---
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||||
|
type: object
|
||||||
|
title: Chain Migration Election Schema - Propose a halt in block production to allow for a version change
|
||||||
|
required:
|
||||||
|
- operation
|
||||||
|
- assets
|
||||||
|
- outputs
|
||||||
|
properties:
|
||||||
|
operation:
|
||||||
|
type: string
|
||||||
|
value: "CHAIN_MIGRATION_ELECTION"
|
||||||
|
assets:
|
||||||
|
type: array
|
||||||
|
minItems: 1
|
||||||
|
maxItems: 1
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/asset"
|
||||||
|
outputs:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/output"
|
||||||
|
definitions:
|
||||||
|
asset:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
seed:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- data
|
||||||
|
output:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
condition:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- uri
|
||||||
|
properties:
|
||||||
|
uri:
|
||||||
|
type: string
|
||||||
|
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})[?]\
|
||||||
|
(fpt=ed25519-sha-256(&)?|cost=[0-9]+(&)?|\
|
||||||
|
subtypes=ed25519-sha-256(&)?){2,3}$"
|
@ -0,0 +1,42 @@
|
|||||||
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
|
# Planetmint and IPDB software contributors.
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
---
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||||
|
type: object
|
||||||
|
title: Transaction Schema - CREATE specific constraints
|
||||||
|
required:
|
||||||
|
- assets
|
||||||
|
- inputs
|
||||||
|
properties:
|
||||||
|
assets:
|
||||||
|
type: array
|
||||||
|
minItems: 1
|
||||||
|
maxItems: 1
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/asset"
|
||||||
|
inputs:
|
||||||
|
type: array
|
||||||
|
title: "Transaction inputs"
|
||||||
|
maxItems: 1
|
||||||
|
minItems: 1
|
||||||
|
items:
|
||||||
|
type: "object"
|
||||||
|
required:
|
||||||
|
- fulfills
|
||||||
|
properties:
|
||||||
|
fulfills:
|
||||||
|
type: "null"
|
||||||
|
definitions:
|
||||||
|
asset:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
anyOf:
|
||||||
|
- type: object
|
||||||
|
additionalProperties: true
|
||||||
|
- type: 'null'
|
||||||
|
required:
|
||||||
|
- data
|
@ -0,0 +1,39 @@
|
|||||||
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
|
# Planetmint and IPDB software contributors.
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
---
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||||
|
type: object
|
||||||
|
title: Transaction Schema - TRANSFER specific properties
|
||||||
|
required:
|
||||||
|
- assets
|
||||||
|
properties:
|
||||||
|
assets:
|
||||||
|
type: array
|
||||||
|
minItems: 1
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/asset"
|
||||||
|
inputs:
|
||||||
|
type: array
|
||||||
|
title: "Transaction inputs"
|
||||||
|
minItems: 1
|
||||||
|
items:
|
||||||
|
type: "object"
|
||||||
|
required:
|
||||||
|
- fulfills
|
||||||
|
properties:
|
||||||
|
fulfills:
|
||||||
|
type: "object"
|
||||||
|
definitions:
|
||||||
|
sha3_hexdigest:
|
||||||
|
pattern: "[0-9a-f]{64}"
|
||||||
|
type: string
|
||||||
|
asset:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
"$ref": "#/definitions/sha3_hexdigest"
|
||||||
|
required:
|
||||||
|
- id
|
@ -0,0 +1,74 @@
|
|||||||
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
|
# Planetmint and IPDB software contributors.
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
---
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||||
|
type: object
|
||||||
|
title: Validator Election Schema - Propose a change to validator set
|
||||||
|
required:
|
||||||
|
- operation
|
||||||
|
- assets
|
||||||
|
- outputs
|
||||||
|
properties:
|
||||||
|
operation:
|
||||||
|
type: string
|
||||||
|
value: "VALIDATOR_ELECTION"
|
||||||
|
assets:
|
||||||
|
type: array
|
||||||
|
minItems: 1
|
||||||
|
maxItems: 1
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/asset"
|
||||||
|
outputs:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/output"
|
||||||
|
definitions:
|
||||||
|
output:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
condition:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- uri
|
||||||
|
properties:
|
||||||
|
uri:
|
||||||
|
type: string
|
||||||
|
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})[?]\
|
||||||
|
(fpt=ed25519-sha-256(&)?|cost=[0-9]+(&)?|\
|
||||||
|
subtypes=ed25519-sha-256(&)?){2,3}$"
|
||||||
|
asset:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
data:
|
||||||
|
additionalProperties: false
|
||||||
|
properties:
|
||||||
|
node_id:
|
||||||
|
type: string
|
||||||
|
seed:
|
||||||
|
type: string
|
||||||
|
public_key:
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
|
required:
|
||||||
|
- value
|
||||||
|
- type
|
||||||
|
properties:
|
||||||
|
value:
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- ed25519-base16
|
||||||
|
- ed25519-base32
|
||||||
|
- ed25519-base64
|
||||||
|
power:
|
||||||
|
"$ref": "#/definitions/positiveInteger"
|
||||||
|
required:
|
||||||
|
- node_id
|
||||||
|
- public_key
|
||||||
|
- power
|
||||||
|
required:
|
||||||
|
- data
|
@ -0,0 +1,34 @@
|
|||||||
|
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||||
|
# Planetmint and IPDB software contributors.
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
|
---
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
||||||
|
type: object
|
||||||
|
title: Vote Schema - Vote on an election
|
||||||
|
required:
|
||||||
|
- operation
|
||||||
|
- outputs
|
||||||
|
properties:
|
||||||
|
operation:
|
||||||
|
type: string
|
||||||
|
value: "VOTE"
|
||||||
|
outputs:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
"$ref": "#/definitions/output"
|
||||||
|
definitions:
|
||||||
|
output:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
condition:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- uri
|
||||||
|
properties:
|
||||||
|
uri:
|
||||||
|
type: string
|
||||||
|
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})[?]\
|
||||||
|
(fpt=ed25519-sha-256(&)?|cost=[0-9]+(&)?|\
|
||||||
|
subtypes=ed25519-sha-256(&)?){2,3}$"
|
Loading…
x
Reference in New Issue
Block a user