Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Coin Model #30

Merged
merged 4 commits into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@
"amount": {
"$ref":"#/components/schemas/Amount"
},
"coin_change": {
"$ref":"#/components/schemas/CoinChange"
},
"metadata": {
"type":"object",
"example": {
Expand Down Expand Up @@ -1190,6 +1193,60 @@
"ed25519"
]
},
"CoinAction": {
"description":"CoinActions are different state changes that a Coin can undergo. When a Coin is created, it is coin_created. When a Coin is spent, it is coin_spent. It is assumed that a single Coin cannot be created or spent more than once.",
"type":"string",
"enum": [
"coin_created",
"coin_spent"
]
},
"CoinIdentifier": {
"description":"CoinIdentifier uniquely identifies a Coin.",
"type":"object",
"required": [
"identifier"
],
"properties": {
"identifier": {
"description":"Identifier should be populated with a globally unique identifier of a Coin. In Bitcoin, this identifier would be transaction_hash:index.",
"type":"string",
"example":"0x2f23fd8cca835af21f3ac375bac601f97ead75f2e79143bdf71fe2c4be043e8f:1"
}
}
},
"CoinChange": {
"description":"CoinChange is used to represent a change in state of a some coin identified by a coin_identifier. This object is part of the Operation model and must be populated for UTXO-based blockchains. Coincidentally, this abstraction of UTXOs allows for supporting both account-based transfers and UTXO-based transfers on the same blockchain (when a transfer is account-based, don't populate this model).",
"type":"object",
"required": [
"coin_identifier",
"coin_action"
],
"properties": {
"coin_identifier": {
"$ref":"#/components/schemas/CoinIdentifier"
},
"coin_action": {
"$ref":"#/components/schemas/CoinAction"
}
}
},
"Coin": {
"description":"Coin contains its unique identifier and the amount it represents.",
"type":"object",
"required": [
"coin_identifier",
"amount"
],
"properties": {
"coin_identifier": {
"$ref":"#/components/schemas/CoinIdentifier"
},
"amount": {
"$ref":"#/components/schemas/Amount"
}
}
},
"AccountBalanceRequest": {
"description":"An AccountBalanceRequest is utilized to make a balance request on the /account/balance endpoint. If the block_identifier is populated, a historical balance query should be performed.",
"type":"object",
Expand Down Expand Up @@ -1227,6 +1284,13 @@
"$ref":"#/components/schemas/Amount"
}
},
"coins": {
"type":"array",
"description":"If a blockchain is UTXO-based, all unspent Coins owned by an account_identifier should be returned alongside the balance. It is highly recommended to populate this field so that users of the Rosetta API implementation don't need to maintain their own indexer to track their UTXOs.",
"items": {
"$ref":"#/components/schemas/Coin"
}
},
"metadata": {
"description":"Account-based blockchains that utilize a nonce or sequence number should include that number in the metadata. This number could be unique to the identifier or global across the account address.",
"type":"object",
Expand Down
17 changes: 17 additions & 0 deletions api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,14 @@ components:
$ref: 'models/Signature.yaml'
SignatureType:
$ref: 'models/SignatureType.yaml'
CoinAction:
$ref: 'models/CoinAction.yaml'
CoinIdentifier:
$ref: 'models/CoinIdentifier.yaml'
CoinChange:
$ref: 'models/CoinChange.yaml'
Coin:
$ref: 'models/Coin.yaml'

# Request/Responses
AccountBalanceRequest:
Expand Down Expand Up @@ -647,6 +655,15 @@ components:
A single account may have a balance in multiple currencies.
items:
$ref: '#/components/schemas/Amount'
coins:
type: array
description: |
If a blockchain is UTXO-based, all unspent Coins owned by an account_identifier
should be returned alongside the balance. It is highly recommended to
populate this field so that users of the Rosetta API implementation
don't need to maintain their own indexer to track their UTXOs.
items:
$ref: '#/components/schemas/Coin'
metadata:
description: |
Account-based blockchains that utilize a nonce or sequence number
Expand Down
26 changes: 26 additions & 0 deletions models/Coin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020 Coinbase, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

description: |
Coin contains its unique identifier and the amount
it represents.
type: object
required:
- coin_identifier
- amount
properties:
coin_identifier:
$ref: 'CoinIdentifier.yaml'
amount:
$ref: 'Amount.yaml'
23 changes: 23 additions & 0 deletions models/CoinAction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2020 Coinbase, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

description: |
CoinActions are different state changes that a Coin can
undergo. When a Coin is created, it is coin_created. When a Coin is
spent, it is coin_spent. It is assumed that a single Coin
cannot be created or spent more than once.
type: string
enum:
- coin_created
- coin_spent
33 changes: 33 additions & 0 deletions models/CoinChange.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2020 Coinbase, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

description: |
CoinChange is used to represent a change in state of
a some coin identified by a coin_identifier. This object
is part of the Operation model and must be populated for
UTXO-based blockchains.

Coincidentally, this abstraction of UTXOs allows for supporting
both account-based transfers and UTXO-based transfers on the
same blockchain (when a transfer is account-based, don't
populate this model).
type: object
required:
- coin_identifier
- coin_action
properties:
coin_identifier:
$ref: 'CoinIdentifier.yaml'
coin_action:
$ref: 'CoinAction.yaml'
26 changes: 26 additions & 0 deletions models/CoinIdentifier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020 Coinbase, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

description: |
CoinIdentifier uniquely identifies a Coin.
type: object
required:
- identifier
properties:
identifier:
description: |
Identifier should be populated with a globally unique identifier
of a Coin. In Bitcoin, this identifier would be transaction_hash:index.
type: string
example: "0x2f23fd8cca835af21f3ac375bac601f97ead75f2e79143bdf71fe2c4be043e8f:1"
2 changes: 2 additions & 0 deletions models/Operation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ properties:
$ref: 'AccountIdentifier.yaml'
amount:
$ref: 'Amount.yaml'
coin_change:
$ref: 'CoinChange.yaml'
metadata:
type: object
example:
Expand Down