Skip to content

Commit

Permalink
Restructure message types
Browse files Browse the repository at this point in the history
- Seperate Mint/Burn/BatchMint/BatchBurn
- Merge TransferFrom and SendFrom
  • Loading branch information
yihuang committed Mar 19, 2021
1 parent 16d0158 commit 401063d
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 105 deletions.
21 changes: 11 additions & 10 deletions packages/cw1155/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ must not both be `None` at the same time.

### Messages

`TransferFrom{from, to, token_id, value}` - This transfers some amount of tokens between two accounts. The operator
should either be the `from` account or have approval from it.
`SendFrom{from, to, token_id, value, msg}` - This transfers some amount of tokens between two accounts. If `to` is an address controlled by a smart contract, it must implement the `CW1155Receiver` interface, `msg` will be passed to it along with other fields, otherwise, `msg` should be `None`. The operator should
either be the `from` account or have approval from it.

`SendFrom{from, to, token_id, value, msg}` - This transfers some amount of tokens between two accounts. `to`
must be an address controlled by a smart contract, which implements the `CW1155Receiver` interface. The operator should
either be the `from` account or have approval from it. The `msg` will be passed to the recipient contract, along with
the other fields.
`BatchSendFrom{from, to, batch: Vec<(token_id, value)>, msg}` - Batched version of `SendFrom` which can handle multiple types of tokens at
once.

`BatchTransferFrom{from, to, batch}` - Batched version of `TransferFrom` which can handle multiple types of tokens at once.
`Mint {to, token_id, value, msg}` - This mints some tokens to `to` account, If `to` is controlled by a smart contract, it should implement `CW1155Receiver` interface, `msg` will be passed to it along with other fields, otherwise, `msg` should be `None`.

`BatchSendFrom{from, contract, batch, msg}` - Batched version of `SendFrom` which can handle multiple types of tokens at
once.
`BatchMint {to, batch: Vec<(token_id, value)>, msg}` - Batched version of `Mint`.

`Burn {from, token_id, value}` - This burns some tokens from `from` account.

`BatchBurn {from, batch: Vec<(token_id, value)>}` - Batched version of `Burn`.

`ApproveAll{ operator, expires }` - Allows operator to transfer / send any token from the owner's account. If expiration
is set, then this allowance has a time/height limit.
Expand All @@ -53,7 +54,7 @@ exist.
tokens. Return type is `ApprovedForAllResponse`. If `include_expired` is set, show expired owners in the results,
otherwise, ignore them.

`ApprovedForAllItem{owner, operator}` - Query approved status `owner` granted to `operator`. Return type is
`ApprovedForAllItem{owner, operator}` - Query approved status `owner` granted to `operator`. Return type is
`ApprovedForAllItemResponse`.

### Receiver
Expand Down
10 changes: 2 additions & 8 deletions packages/cw1155/schema/cw1155_batch_receive_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "object",
"required": [
"batch",
"msg",
"operator"
],
"properties": {
Expand Down Expand Up @@ -35,14 +36,7 @@
]
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"operator": {
"$ref": "#/definitions/HumanAddr"
Expand Down
169 changes: 117 additions & 52 deletions packages/cw1155/schema/cw1155_handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@
"title": "Cw1155HandleMsg",
"anyOf": [
{
"description": "TransferFrom is a base message to move tokens. if `env.sender` is the owner or has sufficient pre-approval.",
"description": "SendFrom is a base message to move tokens, if `env.sender` is the owner or has sufficient pre-approval.",
"type": "object",
"required": [
"transfer_from"
"send_from"
],
"properties": {
"transfer_from": {
"send_from": {
"type": "object",
"required": [
"from",
"to",
"token_id",
"value"
],
"properties": {
"from": {
"$ref": "#/definitions/HumanAddr"
},
"msg": {
"description": "`None` means don't call the receiver interface",
"anyOf": [
{
"$ref": "#/definitions/HumanAddr"
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
},
"to": {
"anyOf": [
"description": "If `to` is not contract, `msg` should be `None`",
"allOf": [
{
"$ref": "#/definitions/HumanAddr"
},
{
"type": "null"
}
]
},
Expand All @@ -47,34 +51,79 @@
}
},
{
"description": "SendFrom is a base message to move tokens to contract. if `env.sender` is the owner or has sufficient pre-approval.",
"description": "BatchSendFrom is a base message to move multiple types of tokens in batch, if `env.sender` is the owner or has sufficient pre-approval.",
"type": "object",
"required": [
"send_from"
"batch_send_from"
],
"properties": {
"send_from": {
"batch_send_from": {
"type": "object",
"required": [
"contract",
"token_id",
"value"
"batch",
"from",
"to"
],
"properties": {
"contract": {
"$ref": "#/definitions/HumanAddr"
"batch": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "string"
},
{
"$ref": "#/definitions/Uint128"
}
],
"maxItems": 2,
"minItems": 2
}
},
"from": {
"$ref": "#/definitions/HumanAddr"
},
"msg": {
"description": "`None` means don't call the receiver interface",
"anyOf": [
{
"$ref": "#/definitions/HumanAddr"
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
},
"to": {
"description": "if `to` is not contract, `msg` should be `None`",
"allOf": [
{
"$ref": "#/definitions/HumanAddr"
}
]
}
}
}
}
},
{
"description": "Mint is a base message to mint tokens.",
"type": "object",
"required": [
"mint"
],
"properties": {
"mint": {
"type": "object",
"required": [
"to",
"token_id",
"value"
],
"properties": {
"msg": {
"description": "`None` means don't call the receiver interface",
"anyOf": [
{
"$ref": "#/definitions/Binary"
Expand All @@ -84,6 +133,14 @@
}
]
},
"to": {
"description": "If `to` is not contract, `msg` should be `None`",
"allOf": [
{
"$ref": "#/definitions/HumanAddr"
}
]
},
"token_id": {
"type": "string"
},
Expand All @@ -95,16 +152,17 @@
}
},
{
"description": "BatchTransferFrom is a base message to move tokens to another account without triggering actions. if `env.sender` is the owner or has sufficient pre-approval.",
"description": "BatchMint is a base message to mint multiple types of tokens in batch.",
"type": "object",
"required": [
"batch_transfer_from"
"batch_mint"
],
"properties": {
"batch_transfer_from": {
"batch_mint": {
"type": "object",
"required": [
"batch"
"batch",
"to"
],
"properties": {
"batch": {
Expand All @@ -123,23 +181,22 @@
"minItems": 2
}
},
"from": {
"msg": {
"description": "`None` means don't call the receiver interface",
"anyOf": [
{
"$ref": "#/definitions/HumanAddr"
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
},
"to": {
"anyOf": [
"description": "If `to` is not contract, `msg` should be `None`",
"allOf": [
{
"$ref": "#/definitions/HumanAddr"
},
{
"type": "null"
}
]
}
Expand All @@ -148,17 +205,45 @@
}
},
{
"description": "BatchSendFrom is a base message to move tokens to another to without triggering actions. if `env.sender` is the owner or has sufficient pre-approval.",
"description": "Burn is a base message to burn tokens.",
"type": "object",
"required": [
"batch_send_from"
"burn"
],
"properties": {
"batch_send_from": {
"burn": {
"type": "object",
"required": [
"from",
"token_id",
"value"
],
"properties": {
"from": {
"$ref": "#/definitions/HumanAddr"
},
"token_id": {
"type": "string"
},
"value": {
"$ref": "#/definitions/Uint128"
}
}
}
}
},
{
"description": "BatchBurn is a base message to burn multiple types of tokens in batch.",
"type": "object",
"required": [
"batch_burn"
],
"properties": {
"batch_burn": {
"type": "object",
"required": [
"batch",
"contract"
"from"
],
"properties": {
"batch": {
Expand All @@ -177,28 +262,8 @@
"minItems": 2
}
},
"contract": {
"$ref": "#/definitions/HumanAddr"
},
"from": {
"anyOf": [
{
"$ref": "#/definitions/HumanAddr"
},
{
"type": "null"
}
]
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/HumanAddr"
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions packages/cw1155/schema/cw1155_receive_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "object",
"required": [
"amount",
"msg",
"operator",
"token_id"
],
Expand All @@ -24,14 +25,7 @@
]
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"operator": {
"description": "The account that executed the send message",
Expand Down
Loading

0 comments on commit 401063d

Please sign in to comment.