Skip to content

Commit

Permalink
new transactions (#178)
Browse files Browse the repository at this point in the history
* added a new theoretical structure for transactions, signatures, and types

* added drop schema payload

* made changes discussed this morning

* modified repo to reflect new transaction structure

* updated CLI to use stubbed out methods.  Should now be building

* removed old packages
  • Loading branch information
brennanjl committed Feb 26, 2024
1 parent 4b376f8 commit 2197a2c
Show file tree
Hide file tree
Showing 78 changed files with 2,214 additions and 2,494 deletions.
166 changes: 107 additions & 59 deletions api/openapi-spec/api/v1/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,40 @@
}
},
"definitions": {
"ExtensionsExtensionConfig": {
"type": "object",
"properties": {
"argument": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"TransactionBody": {
"type": "object",
"properties": {
"payload": {
"type": "string",
"format": "byte"
},
"payloadType": {
"type": "string"
},
"fee": {
"type": "string"
},
"nonce": {
"type": "string",
"format": "uint64"
},
"salt": {
"type": "string",
"format": "byte"
}
}
},
"protobufAny": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -504,15 +538,15 @@
"type": "object",
"properties": {
"tx": {
"$ref": "#/definitions/txTx"
"$ref": "#/definitions/txTransaction"
}
}
},
"txBroadcastResponse": {
"type": "object",
"properties": {
"receipt": {
"$ref": "#/definitions/txTxReceipt"
"status": {
"$ref": "#/definitions/txTransactionStatus"
}
}
},
Expand All @@ -527,7 +561,8 @@
"$ref": "#/definitions/txSignature"
},
"sender": {
"type": "string"
"type": "string",
"format": "byte"
}
}
},
Expand Down Expand Up @@ -557,41 +592,35 @@
}
}
},
"txDataset": {
"txEstimatePriceRequest": {
"type": "object",
"properties": {
"owner": {
"type": "string"
},
"name": {
"type": "string"
},
"tables": {
"type": "array",
"items": {
"$ref": "#/definitions/txTable"
}
},
"actions": {
"type": "array",
"items": {
"$ref": "#/definitions/txAction"
}
"tx": {
"$ref": "#/definitions/txTransaction"
}
}
},
"txEstimatePriceRequest": {
"txEstimatePriceResponse": {
"type": "object",
"properties": {
"tx": {
"$ref": "#/definitions/txTx"
"price": {
"type": "string"
}
}
},
"txEstimatePriceResponse": {
"txExtensions": {
"type": "object",
"properties": {
"price": {
"name": {
"type": "string"
},
"initialization": {
"type": "array",
"items": {
"$ref": "#/definitions/ExtensionsExtensionConfig"
}
},
"alias": {
"type": "string"
}
}
Expand Down Expand Up @@ -622,8 +651,8 @@
"txGetSchemaResponse": {
"type": "object",
"properties": {
"dataset": {
"$ref": "#/definitions/txDataset"
"schema": {
"$ref": "#/definitions/txSchema"
}
}
},
Expand Down Expand Up @@ -702,6 +731,35 @@
],
"default": "OK"
},
"txSchema": {
"type": "object",
"properties": {
"owner": {
"type": "string"
},
"name": {
"type": "string"
},
"tables": {
"type": "array",
"items": {
"$ref": "#/definitions/txTable"
}
},
"actions": {
"type": "array",
"items": {
"$ref": "#/definitions/txAction"
}
},
"extensions": {
"type": "array",
"items": {
"$ref": "#/definitions/txExtensions"
}
}
}
},
"txSignature": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -735,49 +793,39 @@
}
}
},
"txTx": {
"txTransaction": {
"type": "object",
"properties": {
"hash": {
"type": "string",
"format": "byte"
},
"payload_type": {
"type": "integer",
"format": "int32"
},
"payload": {
"type": "string",
"format": "byte"
},
"nonce": {
"type": "string",
"format": "int64"
"body": {
"$ref": "#/definitions/TransactionBody"
},
"signature": {
"$ref": "#/definitions/txSignature"
},
"fee": {
"type": "string"
},
"sender": {
"type": "string"
"type": "string",
"format": "byte"
}
}
},
"txTxReceipt": {
"txTransactionStatus": {
"type": "object",
"properties": {
"txHash": {
"id": {
"type": "string",
"format": "byte"
},
"fee": {
"type": "string"
},
"body": {
"type": "string",
"format": "byte"
"status": {
"type": "string"
},
"errors": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -805,16 +853,16 @@
"type": "object",
"properties": {
"tx": {
"$ref": "#/definitions/txTx"
"$ref": "#/definitions/txTransaction"
}
},
"title": "If power is 0, the validator will be removed from the validator set\nIf power is \u003e 0, if the validator is in the approved validator list, validator will be added to the validator set\nBase64 encoded both pubkey and validator power"
"title": "TODO: these should not wrap Transactions; all of these should just get forwarded to the broadcast endpoint"
},
"txValidatorJoinResponse": {
"type": "object",
"properties": {
"receipt": {
"$ref": "#/definitions/txTxReceipt"
"$ref": "#/definitions/txTransactionStatus"
}
}
},
Expand Down Expand Up @@ -854,15 +902,15 @@
"type": "object",
"properties": {
"tx": {
"$ref": "#/definitions/txTx"
"$ref": "#/definitions/txTransaction"
}
}
},
"txValidatorLeaveResponse": {
"type": "object",
"properties": {
"receipt": {
"$ref": "#/definitions/txTxReceipt"
"$ref": "#/definitions/txTransactionStatus"
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/kwil-cli/cmds/common/display/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package display

import (
"fmt"
txTypes "github.com/kwilteam/kwil-db/pkg/tx"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/kwilteam/kwil-db/pkg/transactions"
)

func PrintTxResponse(res *txTypes.Receipt) {
if res.TxHash != nil {
func PrintTxResponse(res *transactions.TransactionStatus) {
if res.ID != nil {
fmt.Println("Success!")
}
fmt.Println("Response:")
fmt.Println(" Hash:", hexutil.Encode(res.TxHash))
fmt.Println(" Hash:", hexutil.Encode(res.ID))
fmt.Println(" Fee:", res.Fee)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/kwil-cli/cmds/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func promptGRPCURL(conf *config.KwilCliConfig) error {
func promptPrivateKey(conf *config.KwilCliConfig) error {
prompt := &common.Prompter{
Label: "Private Key",
Default: crypto.HexFromECDSAPrivateKey(conf.PrivateKey),
Default: conf.PrivateKey.Hex(),
}
res, err := prompt.Run()
if err != nil {
Expand All @@ -85,7 +85,7 @@ func promptPrivateKey(conf *config.KwilCliConfig) error {
return nil
}

pk, err := crypto.ECDSAFromHex(res)
pk, err := crypto.PrivateKeyFromHex(res)
if err != nil {
fmt.Println(`invalid private key. key could not be converted to hex. received: `, res)
promptAskAgain := &common.Prompter{
Expand Down
28 changes: 27 additions & 1 deletion cmd/kwil-cli/cmds/database/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/kwilteam/kwil-db/cmd/kwil-cli/config"
"github.com/kwilteam/kwil-db/pkg/client"
"github.com/kwilteam/kwil-db/pkg/csv"
"github.com/kwilteam/kwil-db/pkg/transactions"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -59,7 +60,17 @@ The execution is treated as a single transaction, and will either succeed or fai
return fmt.Errorf("error building inputs: %w", err)
}

receipt, err := client.ExecuteAction(ctx, dbid, strings.ToLower(action), inputs)
actionStructure, err := getAction(ctx, client, dbid, action)
if err != nil {
return fmt.Errorf("error getting action: %w", err)
}

tuples, err := createActionInputs(inputs, actionStructure)
if err != nil {
return fmt.Errorf("error creating action inputs: %w", err)
}

receipt, err := client.ExecuteAction(ctx, dbid, strings.ToLower(action), tuples...)
if err != nil {
return fmt.Errorf("error executing action: %w", err)
}
Expand All @@ -85,6 +96,21 @@ The execution is treated as a single transaction, and will either succeed or fai
return cmd
}

func getAction(ctx context.Context, c *client.Client, dbid, action string) (*transactions.Action, error) {
schema, err := c.GetSchema(context.Background(), dbid)
if err != nil {
return nil, fmt.Errorf("error getting schema: %w", err)
}

for _, a := range schema.Actions {
if a.Name == action {
return a, nil
}
}

return nil, fmt.Errorf("action not found: %s", action)
}

// buildInputs builds the inputs for the file
func buildInputs(file *os.File, fileType string, columnMappingFlag []string, inputMappings []string) ([]map[string]any, error) {
switch fileType {
Expand Down
Loading

0 comments on commit 2197a2c

Please sign in to comment.