Skip to content

Commit

Permalink
added swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
0xluk committed Sep 11, 2024
1 parent 6900088 commit 1ebc85f
Show file tree
Hide file tree
Showing 46 changed files with 1,575 additions and 16 deletions.
5 changes: 2 additions & 3 deletions app/qubic-node-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"github.com/pkg/errors"
"github.com/qubic/go-qubic/internal/connector"
"github.com/qubic/go-qubic/server"
Expand Down Expand Up @@ -53,14 +52,14 @@ func run() error {
if err != nil {
return errors.Wrap(err, "generating config usage")
}
fmt.Println(usage)
log.Println(usage)
return nil
case errors.Is(err, conf.ErrVersionWanted):
version, err := conf.VersionString(prefix, &cfg)
if err != nil {
return errors.Wrap(err, "generating config version")
}
fmt.Println(version)
log.Println(version)
return nil
}
return errors.Wrap(err, "parsing config")
Expand Down
154 changes: 154 additions & 0 deletions common/smartcontracts/qutil/inputs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package qutil

import (
"bytes"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"github.com/pkg/errors"
"github.com/qubic/go-qubic/common"
)

const (
SmartContractID = 4
SmartContractAddress = "EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVWRF"
)

type InputType int

const (
SendToManyV1InputType InputType = iota + 1
BurnQubicInputType
)

type FunctionType int

const (
GetSendToManyV1FeeFunctionType FunctionType = iota + 1
)

const (
sendManyV1MaxTransfers = 25
)

type sendToManyV1Payload struct {
addresses [sendManyV1MaxTransfers][32]byte
amounts [sendManyV1MaxTransfers]int64
}

func (stm *sendToManyV1Payload) UnmarshalBinary(data []byte) error {
r := bytes.NewReader(data)

err := binary.Read(r, binary.LittleEndian, &stm.addresses)
if err != nil {
return errors.Wrap(err, "reading addresses from reader")
}

err = binary.Read(r, binary.LittleEndian, &stm.amounts)
if err != nil {
return errors.Wrap(err, "reading amounts from reader")
}

return nil
}

func (stm *sendToManyV1Payload) MarshalBinary() ([]byte, error) {
var buf bytes.Buffer

err := binary.Write(&buf, binary.LittleEndian, stm.addresses)
if err != nil {
return nil, errors.Wrap(err, "writing addresses to buffer")
}

err = binary.Write(&buf, binary.LittleEndian, stm.amounts)
if err != nil {
return nil, errors.Wrap(err, "writing amounts to buffer")
}

return buf.Bytes(), nil
}

type SendToManyV1Transfers struct {
Transfers []common.QubicTransfer
TotalAmount int64
}

func (stm *SendToManyV1Transfers) MarshalBinary() ([]byte, error) {
var payload sendToManyV1Payload
for i, transfer := range stm.Transfers {
addressPubkey, err := transfer.DestinationID.ToPubKey(false)
if err != nil {
return nil, errors.Wrapf(err, "converting destination ID: %s to pubkey", transfer.DestinationID)
}

payload.addresses[i] = addressPubkey
payload.amounts[i] = transfer.Amount
}

binaryData, err := payload.MarshalBinary()
if err != nil {
return nil, errors.Wrap(err, "binary marshalling payload")
}

return binaryData, nil
}

func (stm *SendToManyV1Transfers) FromBase64TxInput(input string) error {
data, err := base64.StdEncoding.DecodeString(input)
if err != nil {
return errors.Wrap(err, "decoding base64 tx input")
}

err = stm.FromRawInput(data)
if err != nil {
return errors.Wrap(err, "parsing tx input")
}

return nil
}

func (stm *SendToManyV1Transfers) FromRawInput(input []byte) error {
var payload sendToManyV1Payload
err := payload.UnmarshalBinary(input)
if err != nil {
return errors.Wrap(err, "binary unmarshalling payload")
}

transfers := make([]common.QubicTransfer, 0, len(payload.addresses))
var totalAmount int64
for i, address := range payload.addresses {
if address == [32]byte{} {
continue
}

addressID, err := common.PubKeyToIdentity(address)
if err != nil {
return errors.Wrapf(err, "converting address: %s", hex.EncodeToString(address[:]))
}
amount := payload.amounts[i]
transfers = append(transfers, common.QubicTransfer{
DestinationID: addressID,
Amount: amount,
})
totalAmount += amount
}

stm.Transfers = transfers
stm.TotalAmount = totalAmount

return nil
}

func (stm *SendToManyV1Transfers) FromHexTxInput(input string) error {
data, err := hex.DecodeString(input)
if err != nil {
return errors.Wrap(err, "decoding hex tx input")
}

err = stm.FromRawInput(data)
if err != nil {
return errors.Wrap(err, "parsing tx input")
}

return nil
}
13 changes: 13 additions & 0 deletions common/smartcontracts/qutil/inputs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package qutil

import "testing"

func TestSendToManyV1Transfers_FromHexTxInput(t *testing.T) {
hexInput := "8c94071c9d571258b926f147ec65ac6479f1167bede583c01fd67cf97ba7d6960febfeed8df0187f44815ea757703d70b045c4d2195bf45e8b70503e85de32f7015bdd2e0f8c29b77cac5f9644350f56c2fb328ff242ac83b69dfb409d293b1abc5f3207e126a9c13e26122453741c5382849341b1fc19a1c47eb511b1d24f871cd7e0eedf36737afd65893abf043757edb4178aab0861ea812308381eefc06b3f69829df609fe8e738f3164321b6a6896a089241634dbc872438d765016de3d98a55cbe855f89604333eae1caf8d44120ccbbf063a416197f0153e9d7bda7058a98349a606588fc0a73dccb137946040b902a30dd73894ea81a8543c53d1cb156ae27cea6e59d48dff7b5b8c420104eca9d66e71e3a8c4b81ff983d484ac6cef09971b1735fedc4089250d9bab80e3668ef3adcc2aac06d33bd9fcc89786500ef87ef78bbffe9866fc15460d3f64e0fe3f3152d941cea0600267fe95cb13100dfc1d012fb0b21ebd9fbc970ce4a357e8d5c68726150c9abdab1bff3afe50a44d726652a564cd6cab1fb8a9f22e37300f5c2cc6a3710eb6b77e735a7919ddfe3c9ab1e41f5b57ffd4e10de5a1f65f6456b7303ad4fe075eacef888b012917bfc5bac23541e535159f6c9d5b465a6b8216b715b525e0c00c78f427a2ea64c3c50041433c475d4fbad890fb768b3e52c14d0e10fc507502c6b06f2fb5baa96d2f586769ba2da7b178c3f15577e701eb74887a627cc176b0a06087d40192d43092e010f029c0144026ec5c72a0e29e30c5124c2803f4053a260784966098865946bf013352a1d54a205844eccee090c3310e268c5c63cb5f43c123b2eca63929e71adafef2013d81698c176280beb035b273004d31a9f4877a78230c31123e30f9fa37b63c4bd2ef25ffc5b1f110eb78f4279cdd56b1a25635cebfaf34d397e84b15b42530d0d4c7570bc9bc49672b26a70c70257916a6380c1110f76f296f0707333967fd1fb135b3c1931dc1a77b19057ab9cbd718e45ba434198fb8d0e6dcb145d885aa69a356f21dbd131c60c49ae6b6ee94de8d1b0f0308f2eb0b12044b4d62d1ed63f4288f847d81bc1c8349a0d499226b5d71520c86d03d8f6ab0a67cedb2bd3090000000000ad487c0000000000c50f000000000000820802000000000041dd3400000000008c2a0a00000000007da96500000000009b5d160000000000389902030000000087190600000000003ccc300000000000820802000000000046ee3800000000000a22080000000000051104000000000005110400000000000f330c000000000014441000000000005f434d00000000001e661800000000006ff05f0200000000c9a8a2000000000014f6770000000000913b0e00000000006965550000000000"

var sendToManyV1Transfers SendToManyV1Transfers
err := sendToManyV1Transfers.FromHexTxInput(hexInput)
if err != nil {
t.Error(err)
}
}
8 changes: 8 additions & 0 deletions common/smartcontracts/qutil/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package qutil

import "github.com/qubic/go-qubic/common"

type Tx struct {
SourceID common.Identity
DestID common.Identity
}
5 changes: 5 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,8 @@ func getIDFrom32Bytes(data [32]byte, isLowercase bool) (Identity, error) {

return id, nil
}

type QubicTransfer struct {
DestinationID Identity
Amount int64
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
# Archiver node services
qubic-node-proxy:
image: ghcr.io/qubic/go-qubic:v0.1.2
image: local.go-qubic
container_name: qubic-node-proxy
labels:
# Traefik
Expand Down
8 changes: 5 additions & 3 deletions proto/v1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ all: $(GO)
--grpc-gateway_opt generate_unbound_methods=true $(OPT_ARGS) \
--go_out=paths=source_relative:. *.proto

openapi: quottery_service.proto
protoc --openapiv2_out=logtostderr=true:. $(OPT_ARGS) \
service.proto
openapi:
protoc -I=. --openapiv2_out . \
--openapiv2_opt allow_merge=true,merge_file_name=qubic-integration-rpc $(OPT_ARGS) \
*.proto
jq '. += {"host":"api.qubic.org", "schemes": ["http", "https"]}' qubic-integration-rpc.swagger.json > tmp && mv tmp qubic-integration-rpc.swagger.json

clean:
rm -f *.pb.go
Expand Down
2 changes: 1 addition & 1 deletion clients/core/client.go → sdk/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package core
import (
"context"
"github.com/pkg/errors"
"github.com/qubic/go-qubic/clients/core/nodetypes"
"github.com/qubic/go-qubic/common"
"github.com/qubic/go-qubic/internal/connector"
qubicpb "github.com/qubic/go-qubic/proto/v1"
"github.com/qubic/go-qubic/sdk/core/nodetypes"
)

type Client struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package hrtypes

import (
"github.com/pkg/errors"
"github.com/qubic/go-qubic/clients/core/nodetypes"
"github.com/qubic/go-qubic/common"
"github.com/qubic/go-qubic/sdk/core/nodetypes"
)

func NewSimpleTransferTransaction(sourceID, destinationID string, amount int64, targetTick uint32) (nodetypes.Transaction, error) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion server/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package server

import (
"context"
"github.com/qubic/go-qubic/clients/core"
qubicpb "github.com/qubic/go-qubic/proto/v1"
"github.com/qubic/go-qubic/sdk/core"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand Down
2 changes: 1 addition & 1 deletion server/quottery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package server

import (
"context"
"github.com/qubic/go-qubic/clients/quottery"
"github.com/qubic/go-qubic/common"
qubicpb "github.com/qubic/go-qubic/proto/v1"
"github.com/qubic/go-qubic/sdk/quottery"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand Down
2 changes: 1 addition & 1 deletion server/qx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package server

import (
"context"
"github.com/qubic/go-qubic/clients/qx"
qubicpb "github.com/qubic/go-qubic/proto/v1"
"github.com/qubic/go-qubic/sdk/qx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand Down
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/pkg/errors"
"github.com/qubic/go-qubic/clients/core"
"github.com/qubic/go-qubic/clients/quottery"
"github.com/qubic/go-qubic/clients/qx"
"github.com/qubic/go-qubic/internal/connector"
qubicpb "github.com/qubic/go-qubic/proto/v1"
"github.com/qubic/go-qubic/sdk/core"
"github.com/qubic/go-qubic/sdk/quottery"
"github.com/qubic/go-qubic/sdk/qx"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/reflection"
Expand Down
2 changes: 1 addition & 1 deletion smartcontracts/qutil/sendmany.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"encoding/binary"
"github.com/pkg/errors"
"github.com/qubic/go-qubic/clients/core/nodetypes"
"github.com/qubic/go-qubic/common"
"github.com/qubic/go-qubic/sdk/core/nodetypes"
)

const Address = "EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVWRF"
Expand Down
Binary file added swagger/dist/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added swagger/dist/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions swagger/dist/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
Loading

0 comments on commit 1ebc85f

Please sign in to comment.