Skip to content

Commit

Permalink
feature: node v5.0.0-rc4 support, swagger.json rewriting utils updated
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Oct 10, 2019
1 parent f57b042 commit 0bbef47
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v5.0.0-rc.2
TAG=v5.0.0-rc.4
COMPILER_TAG=v4.0.0-rc5
13 changes: 6 additions & 7 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# Node
The node's `swagger.json` cannot be used out of the box.
1. replace `"$ref": "#/definitions/UInt64"` with `"type": "integer": "format": "uint64"`
2. replace `"$ref": "#/definitions/EncodedPubkey/Hash/Value/ByteArray"` with `"type": "string"`
1. `./simpletextreplacement.sh swagger-stock.json > swagger2.json` replaces `"$ref": "#/definitions/UInt64/32/16"` with `"type": "integer", "format": "uint64/32/16"`, replace `"$ref": "#/definitions/EncodedPubkey/Hash/Value/ByteArray"` with `"type": "string"`
2. `python updatedict.py swagger2.json swagger3.json` adds BigInt to `/definitions/UInt`, makes all implicit `int64`s explicit `uint64`s
3. replace `"$ref": "#/definitions/TxBlockHeight"` with `"$ref": "#/definitions/UInt"`
4. Inconsistency between `OracleResponse/OracleRespond`
5. updatedict.py adds BigInt to `/definitions/UInt`, makes all implicit `int64`s explicit `uint64`s
6. generate the client (using [go-swagger](https://github.com/go-swagger/go-swagger))
5. generate the client (using [go-swagger](https://github.com/go-swagger/go-swagger))

```
rm -rf swagguard/node/* && swagger generate client -f api/swagger.json -A node --with-flatten=minimal --target swagguard/node --tags=external --api-package=operations --client-package=client
rm -rf swagguard/node/* && swagger generate client -f api/swagger3.json -A node --with-flatten=minimal --target swagguard/node --tags=external --api-package=operations --client-package=client
```

7. The node replies with a Generic Transaction but specifies type: "SpendTx" instead of "SpendTxJSON", so the stock generic_tx.go does not pick it up.
6. The node replies with a Generic Transaction but specifies type: "SpendTx" instead of "SpendTxJSON", so the stock generic_tx.go does not pick it up.
TODO: investigate why Python and JS SDKs have no problem with this
`python api/generic_tx_json_fix.py swagguard/node/models/` to bulk edit all `_tx_json.go` files: their `Type()` should return "*Tx" instead of "*TxJSON"
Manually add `generic_tx.go unmarshalGenericTx()`: `case "ChannelCloseMutualTxJSON": add "ChannelCloseMutualTx"` etc for other Tx types

generic_tx_json_fix.py fixes the `*TxJSON` problem partially - you still need to edit generic_tx.go

8. remember to add .String() to Error
7. remember to add .String() to Error


# Compiler
Expand Down
8 changes: 8 additions & 0 deletions api/simpletextreplacement.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sed -e 's/"$ref": "#\/definitions\/UInt64"/"type":"integer", "format":"uint64"/g' $1 |
sed -e 's/"$ref": "#\/definitions\/UInt32"/"type":"integer", "format":"uint32"/g' |
sed -e 's/"$ref": "#\/definitions\/UInt16"/"type":"integer", "format":"uint16"/g' |

sed -e 's/"$ref": "#\/definitions\/EncodedPubkey"/"type":"string"/g' |
sed -e 's/"$ref": "#\/definitions\/EncodedHash"/"type":"string"/g' |
sed -e 's/"$ref": "#\/definitions\/EncodedValue"/"type":"string"/g' |
sed -e 's/"$ref": "#\/definitions\/EncodedByteArray"/"type":"string"/g'
71 changes: 44 additions & 27 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"swagger": "2.0",
"info": {
"description": "This is the [Aeternity](https://www.aeternity.com/) node API.",
"version": "5.0.0-rc.2",
"version": "5.0.0-rc.4",
"title": "Aeternity node",
"termsOfService": "https://www.aeternity.com/terms/",
"contact": {
Expand Down Expand Up @@ -75,6 +75,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -102,6 +103,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -129,6 +131,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -161,6 +164,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -194,6 +198,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -271,7 +276,12 @@
],
"parameters": [
{
"$ref": "#/parameters/HeightIn"
"in": "path",
"name": "height",
"description": "The height",
"required": true,
"type": "integer",
"format": "uint64"
}
],
"responses": {
Expand Down Expand Up @@ -522,6 +532,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -593,7 +604,12 @@
],
"parameters": [
{
"$ref": "#/parameters/HeightIn"
"in": "path",
"name": "height",
"description": "The height",
"required": true,
"type": "integer",
"format": "uint64"
}
],
"responses": {
Expand Down Expand Up @@ -674,7 +690,12 @@
"type": "string"
},
{
"$ref": "#/parameters/HeightIn"
"in": "path",
"name": "height",
"description": "The height",
"required": true,
"type": "integer",
"format": "uint64"
}
],
"responses": {
Expand Down Expand Up @@ -1332,6 +1353,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand All @@ -1353,6 +1375,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -2235,6 +2258,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -2266,7 +2290,13 @@
"type": "string"
},
{
"$ref": "#/parameters/SaltIn"
"in": "query",
"name": "salt",
"description": "Salt",
"required": true,
"type": "integer",
"format": "uint64",
"minimum": 0
}
],
"responses": {
Expand Down Expand Up @@ -2297,6 +2327,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -2325,6 +2356,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful operation",
Expand Down Expand Up @@ -2353,6 +2385,7 @@
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "successful operation",
Expand Down Expand Up @@ -2423,7 +2456,12 @@
],
"parameters": [
{
"$ref": "#/parameters/HeightIn"
"in": "path",
"name": "height",
"description": "The height",
"required": true,
"type": "integer",
"format": "uint64"
}
],
"responses": {
Expand All @@ -2443,27 +2481,6 @@
}
}
},
"parameters": {
"HeightIn": {
"in": "path",
"name": "height",
"description": "The height",
"required": true,
"type": "integer",
"minimum": 0,
"maximum": 18446744073709551615,
"format": "uint64"
},
"SaltIn": {
"in": "query",
"name": "salt",
"description": "Salt",
"required": true,
"type": "integer",
"minimum": 0,
"format": "uint64"
}
},
"definitions": {
"UInt": {
"type": "integer",
Expand Down
12 changes: 8 additions & 4 deletions api/updatedict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pprint import pprint
from dotted.collection import DottedDict
import json
import argparse

json_objects = []
json_leaves = []
Expand Down Expand Up @@ -47,14 +48,17 @@ def add_uint_bigint(data):
data["definitions"]["UInt"] = bigint
return data

with open('rc2.json') as f:
swagger = json.load(f)
parser = argparse.ArgumentParser(description="Modify a swagger.json in ways that cannot be done via simple search/replace")
parser.add_argument('infile', type=open)
parser.add_argument('outfile', type=argparse.FileType('w'))
args = parser.parse_args()

swagger = json.load(args.infile)
traverse(swagger, [])


swagger_n = add_uint_bigint(swagger)
swagger_n = no_implicit_int64(swagger_n)


with open('swaggerD.json', 'w') as fnew:
json.dump(swagger_n, fnew, indent=2)
json.dump(swagger_n, args.outfile, indent=2)

0 comments on commit 0bbef47

Please sign in to comment.