diff --git a/docs/docs.go b/docs/docs.go deleted file mode 100644 index 8cd59d88d..000000000 --- a/docs/docs.go +++ /dev/null @@ -1,997 +0,0 @@ -// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT -// This file was generated by swaggo/swag -package docs - -import ( - "bytes" - "encoding/json" - "strings" - "text/template" - - "github.com/swaggo/swag" -) - -var doc = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{escape .Description}}", - "title": "{{.Title}}", - "contact": {}, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": { - "/_info": { - "get": { - "description": "Show server informations", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "server" - ], - "summary": "Server Info", - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/config.ConfigInfo" - } - } - } - } - }, - "/{ledger}/accounts": { - "get": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "List all accounts", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "pagination cursor, will return accounts after given address (in descending order)", - "name": "after", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "cursor": { - "allOf": [ - { - "$ref": "#/definitions/query.Cursor" - }, - { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/core.Account" - } - } - } - } - ] - } - } - } - ] - } - } - } - } - }, - "/{ledger}/accounts/{accountId}": { - "get": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Get account by address", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "accountId", - "name": "accountId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/core.Account" - } - } - } - ] - } - } - } - } - }, - "/{ledger}/accounts/{accountId}/metadata": { - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "summary": "Add metadata to account", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "accountId", - "name": "accountId", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "Empty response" - }, - "400": { - "description": "" - } - } - } - }, - "/{ledger}/mapping": { - "get": { - "description": "Get ledger mapping", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "contracts" - ], - "summary": "Get mapping", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/core.Mapping" - } - } - } - ] - } - } - } - }, - "put": { - "description": "Update ledger mapping", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "mapping" - ], - "summary": "Put mapping", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "description": "mapping", - "name": "mapping", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/core.Mapping" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/core.Mapping" - } - } - } - ] - } - } - } - } - }, - "/{ledger}/script": { - "post": { - "description": "Execute a Numscript and create the transaction if any", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "script" - ], - "summary": "Execute Numscript", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "description": "script", - "name": "script", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/core.Script" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.ScriptResponse" - } - } - } - } - }, - "/{ledger}/stats": { - "get": { - "description": "Get ledger stats (aggregate metrics on accounts and transactions)\nThe stats for account", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "stats" - ], - "summary": "Get Stats", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/ledger.Stats" - } - } - } - ] - } - } - } - } - }, - "/{ledger}/transactions": { - "get": { - "description": "Get all ledger transactions", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "transactions" - ], - "summary": "Get all Transactions", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "pagination cursor, will return transactions after given txid (in descending order)", - "name": "after", - "in": "query" - }, - { - "type": "string", - "description": "find transactions by reference field", - "name": "reference", - "in": "query" - }, - { - "type": "string", - "description": "find transactions with postings involving given account, either as source or destination", - "name": "account", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "cursor": { - "allOf": [ - { - "$ref": "#/definitions/query.Cursor" - }, - { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/core.Transaction" - } - } - } - } - ] - } - } - } - ] - } - } - } - }, - "post": { - "description": "Create a new ledger transaction\nCommit a new transaction to the ledger", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "transactions" - ], - "summary": "Create Transaction", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "description": "transaction", - "name": "transaction", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/core.TransactionData" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/core.Transaction" - } - } - } - } - ] - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/controllers.ErrorResponse" - } - }, - "409": { - "description": "Conflict", - "schema": { - "$ref": "#/definitions/controllers.ErrorResponse" - } - } - } - } - }, - "/{ledger}/transactions/batch": { - "post": { - "description": "Create a new ledger transactions batch\nCommit a batch of new transactions to the ledger", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "transactions" - ], - "summary": "Create Transactions Batch", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "description": "transactions", - "name": "transactions", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/core.Transactions" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/controllers.BaseResponse" - } - }, - "400": { - "description": "" - } - } - } - }, - "/{ledger}/transactions/{txid}": { - "get": { - "description": "Get transaction by transaction id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "transactions" - ], - "summary": "Get Transaction", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "txid", - "name": "txid", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "allOf": [ - { - "$ref": "#/definitions/controllers.BaseResponse" - }, - { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/core.Transaction" - } - } - } - ] - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/controllers.BaseResponse" - } - } - } - } - }, - "/{ledger}/transactions/{txid}/metadata": { - "post": { - "description": "Set a new metadata to a ledger transaction by transaction id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "transactions" - ], - "summary": "Set Transaction Metadata", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "txid", - "name": "txid", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "Empty response" - } - } - } - }, - "/{ledger}/transactions/{txid}/revert": { - "post": { - "description": "Revert a ledger transaction by transaction id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "transactions" - ], - "summary": "Revert Transaction", - "parameters": [ - { - "type": "string", - "description": "ledger", - "name": "ledger", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "txid", - "name": "txid", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "description": "Empty response" - } - } - } - } - }, - "definitions": { - "config.Config": { - "type": "object", - "properties": { - "storage": { - "$ref": "#/definitions/config.LedgerStorage" - } - } - }, - "config.ConfigInfo": { - "type": "object", - "properties": { - "config": { - "$ref": "#/definitions/config.Config" - }, - "server": { - "type": "string" - }, - "version": {} - } - }, - "config.LedgerStorage": { - "type": "object", - "properties": { - "driver": { - "type": "string" - }, - "ledgers": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "controllers.BaseResponse": { - "type": "object", - "properties": { - "cursor": {}, - "data": {} - } - }, - "controllers.ErrorResponse": { - "type": "object", - "properties": { - "error_code": { - "type": "string", - "enum": [ - "INTERNAL", - "CONFLICT", - "INSUFFICIENT_FUND", - "VALIDATION", - "NOT_FOUND" - ] - }, - "error_message": { - "type": "string" - } - } - }, - "controllers.ScriptResponse": { - "type": "object", - "properties": { - "details": { - "type": "string" - }, - "error_code": { - "type": "string", - "enum": [ - "INTERNAL", - "CONFLICT", - "INSUFFICIENT_FUND", - "VALIDATION", - "NOT_FOUND" - ] - }, - "error_message": { - "type": "string" - } - } - }, - "core.Account": { - "type": "object", - "properties": { - "address": { - "type": "string", - "example": "users:001" - }, - "balances": { - "type": "object", - "additionalProperties": { - "type": "integer" - }, - "example": { - "COIN": 100 - } - }, - "metadata": { - "type": "object" - }, - "type": { - "type": "string", - "example": "virtual" - }, - "volumes": { - "type": "object", - "additionalProperties": { - "type": "object", - "additionalProperties": { - "type": "integer" - } - } - } - } - }, - "core.Contract": { - "type": "object", - "properties": { - "account": { - "type": "string" - }, - "expr": {} - } - }, - "core.Mapping": { - "type": "object", - "properties": { - "contracts": { - "type": "array", - "items": { - "$ref": "#/definitions/core.Contract" - } - } - } - }, - "core.Posting": { - "type": "object", - "properties": { - "amount": { - "type": "integer" - }, - "asset": { - "type": "string" - }, - "destination": { - "type": "string" - }, - "source": { - "type": "string" - } - } - }, - "core.Script": { - "type": "object", - "properties": { - "plain": { - "type": "string" - }, - "vars": { - "type": "object" - } - } - }, - "core.Transaction": { - "type": "object", - "properties": { - "metadata": { - "type": "object" - }, - "postings": { - "type": "array", - "items": { - "$ref": "#/definitions/core.Posting" - } - }, - "reference": { - "type": "string" - }, - "timestamp": { - "type": "string" - }, - "txid": { - "type": "integer" - } - } - }, - "core.TransactionData": { - "type": "object", - "properties": { - "metadata": { - "type": "object" - }, - "postings": { - "type": "array", - "items": { - "$ref": "#/definitions/core.Posting" - } - }, - "reference": { - "type": "string" - } - } - }, - "core.Transactions": { - "type": "object", - "required": [ - "transactions" - ], - "properties": { - "transactions": { - "type": "array", - "items": { - "$ref": "#/definitions/core.TransactionData" - } - } - } - }, - "ledger.Stats": { - "type": "object", - "properties": { - "accounts": { - "type": "integer" - }, - "transactions": { - "type": "integer" - } - } - }, - "query.Cursor": { - "type": "object", - "properties": { - "data": {}, - "has_more": { - "type": "boolean" - }, - "next": { - "type": "string" - }, - "page_size": { - "type": "integer" - }, - "previous": { - "type": "string" - }, - "remaining_results": { - "type": "integer" - }, - "total": { - "type": "integer" - } - } - } - } -}` - -type swaggerInfo struct { - Version string - Host string - BasePath string - Schemes []string - Title string - Description string -} - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = swaggerInfo{ - Version: "1.0", - Host: "localhost:3068", - BasePath: "", - Schemes: []string{"http", "https"}, - Title: "Ledger API", - Description: "", -} - -type s struct{} - -func (s *s) ReadDoc() string { - sInfo := SwaggerInfo - sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) - - t, err := template.New("swagger_info").Funcs(template.FuncMap{ - "marshal": func(v interface{}) string { - a, _ := json.Marshal(v) - return string(a) - }, - "escape": func(v interface{}) string { - // escape tabs - str := strings.Replace(v.(string), "\t", "\\t", -1) - // replace " with \", and if that results in \\", replace that with \\\" - str = strings.Replace(str, "\"", "\\\"", -1) - return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1) - }, - }).Parse(doc) - if err != nil { - return doc - } - - var tpl bytes.Buffer - if err := t.Execute(&tpl, sInfo); err != nil { - return doc - } - - return tpl.String() -} - -func init() { - swag.Register("swagger", &s{}) -} diff --git a/docs/docs.md b/docs/docs.md deleted file mode 100644 index 083ec4a3b..000000000 --- a/docs/docs.md +++ /dev/null @@ -1 +0,0 @@ -Find the complete Numary documentation at [docs.numary.com](https://docs.numary.com) \ No newline at end of file diff --git a/go.mod b/go.mod index 12790349c..d8f8da369 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.16 require ( github.com/XSAM/otelsql v0.10.0 github.com/gin-contrib/cors v1.3.1 - github.com/gin-contrib/logger v0.2.0 // indirect github.com/gin-gonic/gin v1.7.7 github.com/google/go-cmp v0.5.6 github.com/huandu/go-sqlbuilder v1.13.0 @@ -20,7 +19,6 @@ require ( github.com/spf13/cobra v1.3.0 github.com/spf13/viper v1.10.1 github.com/stretchr/testify v1.7.0 - github.com/swaggo/swag v1.7.8 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.28.0 go.opentelemetry.io/otel v1.3.0 go.opentelemetry.io/otel/exporters/jaeger v1.3.0 @@ -35,13 +33,11 @@ require ( go.opentelemetry.io/otel/sdk v1.3.0 go.opentelemetry.io/otel/sdk/metric v0.26.0 go.opentelemetry.io/otel/trace v1.3.0 - go.uber.org/atomic v1.9.0 // indirect go.uber.org/dig v1.13.0 go.uber.org/fx v1.16.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/rs/zerolog v1.26.1 // indirect + gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 272f7d2a9..1fc71e540 100644 --- a/go.sum +++ b/go.sum @@ -59,7 +59,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= @@ -68,9 +67,7 @@ github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpz github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= @@ -78,7 +75,6 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/ github.com/XSAM/otelsql v0.10.0 h1:y8o7q4NaZEV0dBiUC7TuNTHNKyDaX3Z4anntNu7dfYw= github.com/XSAM/otelsql v0.10.0/go.mod h1:7n9dZASOnVJncMmBPQjL5OdjQosb5gryCgsgNISnJVo= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= -github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs= github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -216,7 +212,6 @@ github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA= github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= -github.com/gin-contrib/logger v0.2.0 h1:YkdOGKdm/Nnrrd3bjBjcjd3ow1kR2KUfxxP4/rlL23E= github.com/gin-contrib/logger v0.2.0/go.mod h1:dYxbt3GB+rvPyJSvox5lLsnKYwh8PjWrC9TQtR+hpUw= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -244,17 +239,13 @@ github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jT github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= -github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg= -github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -509,7 +500,6 @@ github.com/jackc/puddle v1.2.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -562,7 +552,6 @@ github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= @@ -627,8 +616,6 @@ github.com/numary/ledger v0.0.0-20210702172952-a5bd30e551d0/go.mod h1:u2K28z9TDY github.com/numary/ledger v0.0.0-20211227131550-dc7b78f85b5b/go.mod h1:uovuDsK7Gs7duqKQ9PgaFulJnPTDftGdR/n3rBRzNIs= github.com/numary/machine v0.0.0-20210702091459-23a82555adbf/go.mod h1:WAFvefAGYNjdDmPtDoZ305F58QDtUJyB0QWN3vzSZao= github.com/numary/machine v0.0.0-20210831114934-e54c99840e08/go.mod h1:KulcZIlMidEjXmuFSGNckmk0pKr4HFKFYy3bB+ksWSQ= -github.com/numary/machine v0.0.0-20211228135133-02d538034686 h1:UBmc1osTD5dun7K8UzFjX8OraASMDaWSQbI8gBYc4QA= -github.com/numary/machine v0.0.0-20211228135133-02d538034686/go.mod h1:lSdeCwegoylxgHOl6wBC9BgOo2N35ra53aTsRybmJsc= github.com/numary/machine v1.0.0 h1:WCs68NGEAuoExkzLyL9HVRG0EssysXcDY/9gLWLYtxM= github.com/numary/machine v1.0.0/go.mod h1:lSdeCwegoylxgHOl6wBC9BgOo2N35ra53aTsRybmJsc= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= @@ -657,7 +644,6 @@ github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/ory/dockertest/v3 v3.8.1 h1:vU/8d1We4qIad2YM0kOwRVtnyue7ExvacPiw1yDm17g= github.com/ory/dockertest/v3 v3.8.1/go.mod h1:wSRQ3wmkz+uSARYMk7kVJFDBGm8x5gSxIhI7NDc+BAQ= -github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE= github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= @@ -724,7 +710,6 @@ github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= -github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc= github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -793,7 +778,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI= -github.com/swaggo/swag v1.7.8 h1:w249t0l/kc/DKMGlS0fppNJQxKyJ8heNaUWB6nsH3zc= github.com/swaggo/swag v1.7.8/go.mod h1:gZ+TJ2w/Ve1RwQsA2IRoSOTidHz6DX+PIG8GWvbnoLU= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -978,7 +962,6 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/pkg/api/controllers/account_controller.go b/pkg/api/controllers/account_controller.go index d79722ad2..2f98574ee 100644 --- a/pkg/api/controllers/account_controller.go +++ b/pkg/api/controllers/account_controller.go @@ -20,15 +20,6 @@ func NewAccountController() AccountController { return AccountController{} } -// GetAccounts godoc -// @Summary List all accounts -// @Schemes -// @Param ledger path string true "ledger" -// @Param after query string true "pagination cursor, will return accounts after given address (in descending order)" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{cursor=query.Cursor{data=[]core.Account}} -// @Router /{ledger}/accounts [get] func (ctl *AccountController) GetAccounts(c *gin.Context) { l, _ := c.Get("ledger") cursor, err := l.(*ledger.Ledger).FindAccounts( @@ -46,15 +37,6 @@ func (ctl *AccountController) GetAccounts(c *gin.Context) { ) } -// GetAccount godoc -// @Summary Get account by address -// @Schemes -// @Param ledger path string true "ledger" -// @Param accountId path string true "accountId" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{data=core.Account} -// @Router /{ledger}/accounts/{accountId} [get] func (ctl *AccountController) GetAccount(c *gin.Context) { l, _ := c.Get("ledger") acc, err := l.(*ledger.Ledger).GetAccount(c.Request.Context(), c.Param("address")) @@ -69,16 +51,6 @@ func (ctl *AccountController) GetAccount(c *gin.Context) { ) } -// PostAccountMetadata godoc -// @Summary Add metadata to account -// @Schemes -// @Param ledger path string true "ledger" -// @Param accountId path string true "accountId" -// @Accept json -// @Produce json -// @Success 204 "Empty response" -// @Failure 400 -// @Router /{ledger}/accounts/{accountId}/metadata [post] func (ctl *AccountController) PostAccountMetadata(c *gin.Context) { l, _ := c.Get("ledger") var m core.Metadata diff --git a/pkg/api/controllers/config_controller.go b/pkg/api/controllers/config_controller.go index 81e8fa55e..4b69c3fcf 100644 --- a/pkg/api/controllers/config_controller.go +++ b/pkg/api/controllers/config_controller.go @@ -1,12 +1,12 @@ package controllers import ( + "bytes" + "gopkg.in/yaml.v2" "net/http" - "github.com/swaggo/swag" - + _ "embed" "github.com/gin-gonic/gin" - _ "github.com/numary/ledger/docs" "github.com/numary/ledger/pkg/config" ) @@ -36,15 +36,6 @@ func NewConfigController(version string, storageDriver string, lister LedgerList } } -// GetInfo godoc -// @Summary Server Info -// @Description Show server informations -// @Tags server -// @Schemes -// @Accept json -// @Produce json -// @Success 200 {object} config.ConfigInfo{} -// @Router /_info [get] func (ctl *ConfigController) GetInfo(c *gin.Context) { ctl.response( c, @@ -62,11 +53,19 @@ func (ctl *ConfigController) GetInfo(c *gin.Context) { ) } -func (ctl *ConfigController) GetDocs(c *gin.Context) { - doc, err := swag.ReadDoc("swagger") +//go:embed swagger.yaml +var swagger string + +func (ctl *ConfigController) GetDocsAsYaml(c *gin.Context) { + c.Writer.Write([]byte(swagger)) +} + +func (ctl *ConfigController) GetDocsAsJSON(c *gin.Context) { + ret := make(map[string]interface{}) + err := yaml.NewDecoder(bytes.NewBufferString(swagger)).Decode(&ret) if err != nil { - c.AbortWithStatus(http.StatusInternalServerError) - return + panic(err) } - c.Writer.Write([]byte(doc)) + + c.JSON(http.StatusOK, ret) } diff --git a/pkg/api/controllers/ledger_controller.go b/pkg/api/controllers/ledger_controller.go index 486d3c650..dbfc7c5e5 100644 --- a/pkg/api/controllers/ledger_controller.go +++ b/pkg/api/controllers/ledger_controller.go @@ -17,17 +17,6 @@ func NewLedgerController() LedgerController { return LedgerController{} } -// GetStats godoc -// @Summary Get Stats -// @Description Get ledger stats (aggregate metrics on accounts and transactions) -// @Tags stats -// @Schemes -// @Description The stats for account -// @Accept json -// @Produce json -// @Param ledger path string true "ledger" -// @Success 200 {object} controllers.BaseResponse{data=ledger.Stats} -// @Router /{ledger}/stats [get] func (ctl *LedgerController) GetStats(c *gin.Context) { l, _ := c.Get("ledger") diff --git a/pkg/api/controllers/mapping_controller.go b/pkg/api/controllers/mapping_controller.go index ced10592f..bb54b0f62 100644 --- a/pkg/api/controllers/mapping_controller.go +++ b/pkg/api/controllers/mapping_controller.go @@ -15,17 +15,6 @@ func NewMappingController() MappingController { return MappingController{} } -// PutMapping godoc -// @Summary Put mapping -// @Description Update ledger mapping -// @Tags mapping -// @Schemes -// @Param ledger path string true "ledger" -// @Param mapping body core.Mapping true "mapping" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{data=core.Mapping} -// @Router /{ledger}/mapping [put] func (ctl *MappingController) PutMapping(c *gin.Context) { l, _ := c.Get("ledger") @@ -44,16 +33,6 @@ func (ctl *MappingController) PutMapping(c *gin.Context) { ctl.response(c, http.StatusOK, mapping) } -// GetMapping godoc -// @Summary Get mapping -// @Description Get ledger mapping -// @Tags contracts -// @Schemes -// @Param ledger path string true "ledger" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{data=core.Mapping} -// @Router /{ledger}/mapping [get] func (ctl *MappingController) GetMapping(c *gin.Context) { l, _ := c.Get("ledger") diff --git a/pkg/api/controllers/script_controller.go b/pkg/api/controllers/script_controller.go index 1f9fa08cc..c9c34e57e 100644 --- a/pkg/api/controllers/script_controller.go +++ b/pkg/api/controllers/script_controller.go @@ -39,17 +39,6 @@ func NewScriptController() ScriptController { return ScriptController{} } -// PostScript godoc -// @Summary Execute Numscript -// @Description Execute a Numscript and create the transaction if any -// @Tags script -// @Schemes -// @Param ledger path string true "ledger" -// @Param script body core.Script true "script" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.ScriptResponse -// @Router /{ledger}/script [post] func (ctl *ScriptController) PostScript(c *gin.Context) { l, _ := c.Get("ledger") diff --git a/pkg/api/controllers/swagger.yaml b/pkg/api/controllers/swagger.yaml new file mode 100644 index 000000000..08136a9a6 --- /dev/null +++ b/pkg/api/controllers/swagger.yaml @@ -0,0 +1,727 @@ +openapi: 3.0.1 +info: + title: Ledger API + contact: {} + version: "1.0" + +paths: + /_info: + get: + tags: + - server + summary: Server Info + description: Show server informations + operationId: getInfo + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ConfigInfoResponse' + /{ledger}/accounts: + get: + summary: List all accounts + operationId: listAccounts + tags: + - accounts + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: after + in: query + description: pagination cursor, will return accounts after given address (in descending order) + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AccountCursorResponse' + /{ledger}/accounts/{accountId}: + get: + summary: Get account by address + operationId: getAccount + tags: + - accounts + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: accountId + in: path + description: accountId + required: true + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AccountResponse' + /{ledger}/accounts/{accountId}/metadata: + post: + summary: Add metadata to account + operationId: addMetadataToAccount + tags: + - accounts + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: accountId + in: path + description: accountId + required: true + schema: + type: string + requestBody: + description: metadata + content: + application/json: + schema: + $ref: '#/components/schemas/Metadata' + required: true + responses: + 204: + description: Empty response + 400: + description: "" + content: {} + /{ledger}/mapping: + get: + tags: + - mapping + operationId: getMapping + summary: Get mapping + description: Get ledger mapping + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/MappingResponse' + put: + tags: + - mapping + operationId: updateMapping + summary: Put mapping + description: Update ledger mapping + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + requestBody: + description: mapping + content: + application/json: + schema: + $ref: '#/components/schemas/Mapping' + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/MappingResponse' + + /{ledger}/script: + post: + tags: + - script + operationId: runScript + summary: Execute Numscript + description: Execute a Numscript and create the transaction if any + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + requestBody: + description: script + content: + application/json: + schema: + $ref: '#/components/schemas/Script' + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/ScriptResult' + + /{ledger}/stats: + get: + tags: + - stats + operationId: readStats + summary: Get Stats + description: |- + Get ledger stats (aggregate metrics on accounts and transactions) + The stats for account + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/StatsResponse' + /{ledger}/transactions: + get: + tags: + - transactions + summary: Get all Transactions + description: Get all ledger transactions + operationId: listTransactions + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: after + in: query + description: pagination cursor, will return transactions after given txid + (in descending order) + schema: + type: string + - name: reference + in: query + description: find transactions by reference field + schema: + type: string + - name: account + in: query + description: find transactions with postings involving given account, either + as source or destination + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TransactionCursorResponse' + post: + tags: + - transactions + summary: Create Transaction + operationId: createTransaction + description: |- + Create a new ledger transaction + Commit a new transaction to the ledger + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + requestBody: + description: transaction + content: + application/json: + schema: + $ref: '#/components/schemas/TransactionData' + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/CreateTransactionResponse' + 400: + description: Commit error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + 409: + description: Confict + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + + /{ledger}/transactions/{txid}: + get: + tags: + - transactions + summary: Get Transaction + description: Get transaction by transaction id + operationId: getTransaction + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: txid + in: path + description: txid + required: true + schema: + type: integer + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TransactionResponse' + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /{ledger}/transactions/{txid}/metadata: + post: + tags: + - transactions + summary: Set Transaction Metadata + operationId: addMetadataOnTransaction + description: Set a new metadata to a ledger transaction by transaction id + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: txid + in: path + description: txid + required: true + schema: + type: integer + requestBody: + description: metadata + content: + application/json: + schema: + $ref: '#/components/schemas/Metadata' + responses: + 204: + description: Empty response + content: {} + /{ledger}/transactions/{txid}/revert: + post: + tags: + - transactions + operationId: revertTransaction + summary: Revert Transaction + description: Revert a ledger transaction by transaction id + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + - name: txid + in: path + description: txid + required: true + schema: + type: integer + responses: + 204: + description: Empty response + content: {} + /{ledger}/transactions/batch: + post: + tags: + - transactions + summary: Create Transactions Batch + operationId: CreateTransactions + description: |- + Create a new ledger transactions batch + Commit a batch of new transactions to the ledger + parameters: + - name: ledger + in: path + description: ledger + required: true + schema: + type: string + requestBody: + description: transactions + content: + application/json: + schema: + $ref: '#/components/schemas/Transactions' + required: true + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TransactionListResponse' + 400: + description: "" + content: + application/json: + schema: + $ref: '#/components/schemas/TransactionCommitErrorResponse' +components: + schemas: + Config: + type: object + properties: + storage: + $ref: '#/components/schemas/LedgerStorage' + required: + - storage + Metadata: + type: object + nullable: true + additionalProperties: {} + ConfigInfo: + type: object + properties: + config: + $ref: '#/components/schemas/Config' + server: + type: string + version: + type: string + required: + - config + - server + - version + LedgerStorage: + type: object + properties: + driver: + type: string + ledgers: + type: array + items: + type: string + required: + - driver + - ledgers + CursorResponse: + type: object + properties: + cursor: + $ref: '#/components/schemas/Cursor' + ScriptResult: + type: object + properties: + details: + type: string + err: + type: string + Account: + type: object + required: + - address + properties: + address: + type: string + example: users:001 + balances: + type: object + additionalProperties: + type: integer + example: + COIN: 100 + metadata: + type: object + properties: {} + type: + type: string + example: virtual + volumes: + type: object + additionalProperties: + type: object + additionalProperties: + type: integer + Contract: + type: object + properties: + account: + type: string + expr: + type: object + required: + - accounts + - expr + Mapping: + type: object + nullable: true + required: + - contracts + properties: + contracts: + type: array + items: + $ref: '#/components/schemas/Contract' + Posting: + type: object + properties: + amount: + type: integer + asset: + type: string + destination: + type: string + source: + type: string + required: + - amount + - asset + - destination + - source + Script: + type: object + properties: + plain: + type: string + vars: + type: object + properties: {} + required: + - plain + Transaction: + type: object + properties: + metadata: + $ref: '#/components/schemas/Metadata' + postings: + type: array + items: + $ref: '#/components/schemas/Posting' + reference: + type: string + timestamp: + type: string + format: date-time + txid: + type: integer + required: + - postings + - timestamp + - txid + TransactionData: + type: object + properties: + metadata: + type: object + properties: {} + postings: + type: array + items: + $ref: '#/components/schemas/Posting' + reference: + type: string + required: + - postings + Transactions: + required: + - transactions + type: object + properties: + transactions: + type: array + items: + $ref: '#/components/schemas/TransactionData' + Stats: + type: object + properties: + accounts: + type: integer + transactions: + type: integer + required: + - accounts + - transactions + Cursor: + type: object + required: + - page_size + - has_more + - page_size + - remaining_results + - total + properties: + has_more: + type: boolean + next: + type: string + page_size: + type: integer + previous: + type: string + remaining_results: + type: integer + total: + type: integer + AccountCursor: + allOf: + - $ref: '#/components/schemas/Cursor' + - properties: + data: + items: + $ref: '#/components/schemas/Account' + type: array + type: object + required: + - data + AccountCursorResponse: + required: + - cursor + properties: + cursor: + $ref: '#/components/schemas/AccountCursor' + TransactionCursor: + allOf: + - $ref: '#/components/schemas/Cursor' + - type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/Transaction' + required: + - data + TransactionCursorResponse: + type: object + required: + - cursor + properties: + cursor: + $ref: '#/components/schemas/TransactionCursor' + TransactionListResponse: + allOf: + - $ref: '#/components/schemas/CursorResponse' + - properties: + data: + items: + $ref: '#/components/schemas/Transaction' + type: array + type: object + required: + - data + CreateTransactionResponse: + type: object + properties: + data: + items: + $ref: '#/components/schemas/Transaction' + type: array + required: + - data + AccountResponse: + properties: + data: + $ref: '#/components/schemas/Account' + type: object + required: + - data + TransactionResponse: + properties: + data: + $ref: '#/components/schemas/Transaction' + type: object + required: + - data + StatsResponse: + properties: + data: + $ref: '#/components/schemas/Stats' + type: object + required: + - data + MappingResponse: + properties: + data: + $ref: '#/components/schemas/Mapping' + type: object + ConfigInfoResponse: + properties: + data: + $ref: '#/components/schemas/ConfigInfo' + type: object + required: + - data + ErrorCode: + type: string + enum: + - INTERNAL + - INSUFFICIENT_FUND + - VALIDATION + - CONFLICT + - NOT_FOUND + ErrorResponse: + type: object + required: + - error_code + properties: + error_code: + $ref: '#/components/schemas/ErrorCode' + error_message: + type: string + TransactionCommitError: + allOf: + - $ref: '#/components/schemas/Transaction' + - type: object + properties: + errorCode: + $ref: '#/components/schemas/ErrorCode' + errorMessage: + type: string + TransactionCommitErrorResponse: + type: object + required: + - data + properties: + data: + type: array + items: + $ref: '#/components/schemas/TransactionCommitError' diff --git a/pkg/api/controllers/transaction_controller.go b/pkg/api/controllers/transaction_controller.go index 45fe4c57a..db5a57014 100644 --- a/pkg/api/controllers/transaction_controller.go +++ b/pkg/api/controllers/transaction_controller.go @@ -46,19 +46,6 @@ func (ctl *TransactionController) handleCommitError(c *gin.Context, err *ledger. } } -// GetTransactions godoc -// @Summary Get all Transactions -// @Description Get all ledger transactions -// @Tags transactions -// @Schemes -// @Param ledger path string true "ledger" -// @Param after query string false "pagination cursor, will return transactions after given txid (in descending order)" -// @Param reference query string false "find transactions by reference field" -// @Param account query string false "find transactions with postings involving given account, either as source or destination" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{cursor=query.Cursor{data=[]core.Transaction}} -// @Router /{ledger}/transactions [get] func (ctl *TransactionController) GetTransactions(c *gin.Context) { l, _ := c.Get("ledger") cursor, err := l.(*ledger.Ledger).FindTransactions( @@ -78,20 +65,6 @@ func (ctl *TransactionController) GetTransactions(c *gin.Context) { ) } -// PostTransaction godoc -// @Summary Create Transaction -// @Description Create a new ledger transaction -// @Tags transactions -// @Schemes -// @Description Commit a new transaction to the ledger -// @Param ledger path string true "ledger" -// @Param transaction body core.TransactionData true "transaction" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{data=[]core.Transaction} -// @Failure 400 {object} controllers.ErrorResponse -// @Failure 409 {object} controllers.ErrorResponse -// @Router /{ledger}/transactions [post] func (ctl *TransactionController) PostTransaction(c *gin.Context) { l, _ := c.Get("ledger") @@ -112,18 +85,6 @@ func (ctl *TransactionController) PostTransaction(c *gin.Context) { ctl.response(c, http.StatusOK, result) } -// GetTransaction godoc -// @Summary Get Transaction -// @Description Get transaction by transaction id -// @Tags transactions -// @Schemes -// @Param ledger path string true "ledger" -// @Param txid path string true "txid" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse{data=core.Transaction} -// @Failure 404 {object} controllers.BaseResponse -// @Router /{ledger}/transactions/{txid} [get] func (ctl *TransactionController) GetTransaction(c *gin.Context) { l, _ := c.Get("ledger") tx, err := l.(*ledger.Ledger).GetTransaction(c.Request.Context(), c.Param("txid")) @@ -138,17 +99,6 @@ func (ctl *TransactionController) GetTransaction(c *gin.Context) { ctl.response(c, http.StatusOK, tx) } -// RevertTransaction godoc -// @Summary Revert Transaction -// @Description Revert a ledger transaction by transaction id -// @Tags transactions -// @Schemes -// @Param ledger path string true "ledger" -// @Param txid path string true "txid" -// @Accept json -// @Produce json -// @Success 204 "Empty response" -// @Router /{ledger}/transactions/{txid}/revert [post] func (ctl *TransactionController) RevertTransaction(c *gin.Context) { l, _ := c.Get("ledger") err := l.(*ledger.Ledger).RevertTransaction(c.Request.Context(), c.Param("txid")) @@ -164,17 +114,6 @@ func (ctl *TransactionController) RevertTransaction(c *gin.Context) { ctl.noContent(c) } -// PostTransactionMetadata godoc -// @Summary Set Transaction Metadata -// @Description Set a new metadata to a ledger transaction by transaction id -// @Tags transactions -// @Schemes -// @Param ledger path string true "ledger" -// @Param txid path string true "txid" -// @Accept json -// @Produce json -// @Success 204 "Empty response" -// @Router /{ledger}/transactions/{txid}/metadata [post] func (ctl *TransactionController) PostTransactionMetadata(c *gin.Context) { l, _ := c.Get("ledger") @@ -194,19 +133,6 @@ func (ctl *TransactionController) PostTransactionMetadata(c *gin.Context) { ctl.noContent(c) } -// PostTransactionsBatch godoc -// @Summary Create Transactions Batch -// @Description Create a new ledger transactions batch -// @Tags transactions -// @Schemes -// @Description Commit a batch of new transactions to the ledger -// @Param ledger path string true "ledger" -// @Param transactions body core.Transactions true "transactions" -// @Accept json -// @Produce json -// @Success 200 {object} controllers.BaseResponse -// @Failure 400 -// @Router /{ledger}/transactions/batch [post] func (ctl *TransactionController) PostTransactionsBatch(c *gin.Context) { l, _ := c.Get("ledger") diff --git a/pkg/api/routes/routes.go b/pkg/api/routes/routes.go index cdfe44d7a..bdec8d35f 100644 --- a/pkg/api/routes/routes.go +++ b/pkg/api/routes/routes.go @@ -106,7 +106,8 @@ func (r *Routes) Engine(cc cors.Config) *gin.Engine { // Default Middlewares engine.Use(globalMiddlewares...) - engine.GET("/swagger.json", r.configController.GetDocs) + engine.GET("/swagger.yaml", r.configController.GetDocsAsYaml) + //engine.GET("/swagger.json", r.configController.GetDocsAsJSON) // API Routes engine.GET("/_info", r.configController.GetInfo)