Skip to content

Commit

Permalink
Merge pull request #96 from onflow/ianthpun/update-json
Browse files Browse the repository at this point in the history
update cadence 1.0 json specs with Authorization
  • Loading branch information
ianthpun committed May 6, 2024
2 parents 15fec10 + 3c6efae commit 8067f65
Showing 1 changed file with 122 additions and 52 deletions.
174 changes: 122 additions & 52 deletions versioned_docs/version-1.0/json-cadence-spec.md
Expand Up @@ -94,7 +94,6 @@ This format includes less type information than a complete [ABI](https://en.wiki
"type": "String",
"value": "..."
}

```

### Example
Expand Down Expand Up @@ -130,7 +129,7 @@ This format includes less type information than a complete [ABI](https://en.wiki

## Integers

`[U]Int`, `[U]Int8`, `[U]Int16`, `[U]Int32`,`[U]Int64`,`[U]Int128`, `[U]Int256`, `Word8`, `Word16`, `Word32`, or `Word64`
`[U]Int`, `[U]Int8`, `[U]Int16`, `[U]Int32`,`[U]Int64`,`[U]Int128`, `[U]Int256`, `Word8`, `Word16`, `Word32`, or `Word64`

Although JSON supports integer literals up to 64 bits, all integer types are encoded as strings for consistency.

Expand Down Expand Up @@ -162,17 +161,17 @@ Although fixed point numbers are implemented as integers, JSON-Cadence uses a de

```json
{
"type": "[U]Fix64",
"value": "<integer>.<fractional>"
"type": "[U]Fix64",
"value": "<integer>.<fractional>"
}
```

### Example

```json
{
"type": "Fix64",
"value": "12.3"
"type": "Fix64",
"value": "12.3"
}
```

Expand Down Expand Up @@ -248,7 +247,7 @@ Dictionaries are encoded as a list of key-value pairs to preserve the determinis
"value": "test"
}
}
],
]
// ...
}
```
Expand Down Expand Up @@ -285,7 +284,7 @@ Composite fields are encoded as a list of name-value pairs in the order in which
"fields": [
{
"name": "power",
"value": {"type": "Int", "value": "1"}
"value": { "type": "Int", "value": "1" }
}
]
}
Expand Down Expand Up @@ -338,7 +337,44 @@ Composite fields are encoded as a list of name-value pairs in the order in which
"type": "Type",
"value": {
"staticType": {
"kind": "Int",
"kind": "Int"
}
}
}
```

---

## InclusiveRange

```json
{
"type": "InclusiveRange",
"value": {
"start": <start_value>,
"end": <end_value>,
"step": <step_value>
}
}
```

### Example

```json
{
"type": "InclusiveRange",
"value": {
"start": {
"type": "Int256",
"value": "10"
},
"end": {
"type": "Int256",
"value": "20"
},
"step": {
"type": "Int256",
"value": "5"
}
}
}
Expand All @@ -352,7 +388,7 @@ Composite fields are encoded as a list of name-value pairs in the order in which
{
"type": "Capability",
"value": {
"path": <path>,
"id": "identifier",
"address": "0x0", // as hex-encoded string with 0x prefix
"borrowType": <type>,
}
Expand All @@ -365,13 +401,7 @@ Composite fields are encoded as a list of name-value pairs in the order in which
{
"type": "Capability",
"value": {
"path": {
"type": "Path",
"value": {
"domain": "public",
"identifier": "someInteger"
}
},
"id": "1",
"address": "0x1",
"borrowType": {
"kind": "Int"
Expand Down Expand Up @@ -510,7 +540,7 @@ These are basic types like `Int`, `String`, or `StoragePath`.
"type": {
"kind": "String"
},
"size":3
"size": 3
}
```

Expand All @@ -536,7 +566,7 @@ These are basic types like `Int`, `String`, or `StoragePath`.
},
"value": {
"kind": "UInt16"
},
}
}
```

Expand Down Expand Up @@ -569,7 +599,7 @@ These are basic types like `Int`, `String`, or `StoragePath`.
"kind": "Resource",
"type": "",
"typeID": "0x3.GreatContract.GreatNFT",
"initializers":[
"initializers": [
[
{
"label": "foo",
Expand Down Expand Up @@ -678,6 +708,7 @@ Initializer types are encoded a list of parameters to the initializer.
<parameter at index 1>,
// ...
],
"purity: "view" | "",
"return": <type>
}
```
Expand All @@ -697,6 +728,7 @@ Initializer types are encoded a list of parameters to the initializer.
}
}
],
"purity": "view",
"return": {
"kind": "String"
}
Expand All @@ -710,7 +742,14 @@ Initializer types are encoded a list of parameters to the initializer.
```json
{
"kind": "Reference",
"authorized": true | false,
"authorization": {
"kind": "Unauthorized" | "EntitlementMapAuthorization" | "EntitlementConjunctionSet" | "EntitlementDisjunctionSet",
"entitlements": [
<entitlement at index 0>,
<entitlement at index 1>
// ...
]
},
"type": <type>
}
```
Expand All @@ -720,7 +759,17 @@ Initializer types are encoded a list of parameters to the initializer.
```json
{
"kind": "Reference",
"authorized": true,
"authorization": {
{
"kind": "EntitlementMapAuthorization",
"entitlements": [
{
"kind": "EntitlementMap",
"typeID": "foo"
}
]
}
},
"type": {
"kind": "String"
}
Expand All @@ -747,25 +796,22 @@ Initializer types are encoded a list of parameters to the initializer.

```json
{
"kind": "Restriction",
"typeID": "0x3.GreatContract.GreatNFT",
"type": {
"kind": "AnyResource",
},
"restrictions": [
"kind": "Intersection",
"typeID": "{0x1.FungibleToken.Receiver}",
"types": [
{
"kind": "ResourceInterface",
"typeID": "0x1.FungibleToken.Receiver",
"fields": [
{
"id": "uuid",
"type": {
"kind": "UInt64"
}
}
],
"initializers": [],
"type": ""
"kind": "ResourceInterface",
"typeID": "0x1.FungibleToken.Receiver",
"fields": [
{
"id": "uuid",
"type": {
"kind": "UInt64"
}
}
],
"initializers": [],
"type": ""
}
]
}
Expand All @@ -789,7 +835,10 @@ Initializer types are encoded a list of parameters to the initializer.
"kind": "Capability",
"type": {
"kind": "Reference",
"authorized": true,
"authorization": {
"kind": "Unauthorized",
"entitlements": null
},
"type": {
"kind": "String"
}
Expand Down Expand Up @@ -825,7 +874,7 @@ Initializer types are encoded a list of parameters to the initializer.
"kind": "String"
},
"typeID": "0x3.GreatContract.GreatEnum",
"initializers":[],
"initializers": [],
"fields": [
{
"id": "rawValue",
Expand All @@ -847,22 +896,43 @@ represented by its type ID.

```json
{
"type":"Type",
"type": "Type",
"value": {
"staticType": {
"kind":"Resource",
"typeID":"0x3.GreatContract.NFT",
"fields":[
{"id":"foo",
"type": {
"kind":"Optional",
"type":"0x3.GreatContract.NFT" // recursive NFT resource type is instead encoded as an ID
"kind": "Resource",
"typeID": "0x3.GreatContract.NFT",
"fields": [
{
"id": "foo",
"type": {
"kind": "Optional",
"type": "0x3.GreatContract.NFT" // recursive NFT resource type is instead encoded as an ID
}
}
],
"initializers":[],
"type":""
"initializers": [],
"type": ""
}
}
}
```

## Inclusive Range Type

```json
{
"kind": "InclusiveRange",
"element": <integer_type>
}
```

### Example

```json
{
"kind": "InclusiveRange",
"element": {
"kind": "Int"
}
}
```

0 comments on commit 8067f65

Please sign in to comment.