lbc_sdk for types instead of lbc itself (less deps)
This commit is contained in:
parent
2b5bce7f6f
commit
9c2d1aa992
3 changed files with 14 additions and 43 deletions
1
go.mod
1
go.mod
|
|
@ -4,5 +4,6 @@ go 1.24.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/gregorybednov/lbc_sdk v0.0.0-20250810102513-432a51e65f76
|
||||||
github.com/spf13/pflag v1.0.7
|
github.com/spf13/pflag v1.0.7
|
||||||
)
|
)
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -1,4 +1,6 @@
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/gregorybednov/lbc_sdk v0.0.0-20250810102513-432a51e65f76 h1:e3A+1v+Mjt8nuJcVnHuhHZuh4052KRLCUBpH4g74rVs=
|
||||||
|
github.com/gregorybednov/lbc_sdk v0.0.0-20250810102513-432a51e65f76/go.mod h1:DBE00+SaYBtD4qw+nOtSTLuF6h9Ia4TkuBMJB+6krik=
|
||||||
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
|
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
|
||||||
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
|
|
||||||
54
main.go
54
main.go
|
|
@ -13,35 +13,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
types "github.com/gregorybednov/lbc_sdk"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommiterTxBody struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
ID string `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
CommiterPubKey string `json:"commiter_pubkey"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PromiseTxBody struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
ID string `json:"id"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Timestamp int64 `json:"timestamp"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommitmentTxBody struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
ID string `json:"id"`
|
|
||||||
PromiseID string `json:"promise_id"`
|
|
||||||
CommiterID string `json:"commiter_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SignedTx struct {
|
|
||||||
Body any `json:"body"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type rpcResp struct {
|
type rpcResp struct {
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
ID any `json:"id"`
|
ID any `json:"id"`
|
||||||
|
|
@ -62,14 +38,6 @@ type rpcResp struct {
|
||||||
} `json:"result"`
|
} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompoundTx struct {
|
|
||||||
Body struct {
|
|
||||||
Promise *PromiseTxBody `json:"promise"`
|
|
||||||
Commitment *CommitmentTxBody `json:"commitment"`
|
|
||||||
} `json:"body"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
}
|
|
||||||
|
|
||||||
const configDir = "./config"
|
const configDir = "./config"
|
||||||
const privKeyPath = configDir + "/ed25519.key"
|
const privKeyPath = configDir + "/ed25519.key"
|
||||||
const pubKeyPath = configDir + "/ed25519.pub"
|
const pubKeyPath = configDir + "/ed25519.pub"
|
||||||
|
|
@ -109,7 +77,7 @@ func ensureKeypair() (ed25519.PublicKey, ed25519.PrivateKey, error) {
|
||||||
return ed25519.PublicKey(pub), ed25519.PrivateKey(priv), nil
|
return ed25519.PublicKey(pub), ed25519.PrivateKey(priv), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendTx(tx SignedTx, rpcURL string) error {
|
func sendTx(tx types.SignedTx, rpcURL string) error {
|
||||||
txBytes, _ := json.Marshal(tx)
|
txBytes, _ := json.Marshal(tx)
|
||||||
txB64 := base64.StdEncoding.EncodeToString(txBytes)
|
txB64 := base64.StdEncoding.EncodeToString(txBytes)
|
||||||
final := map[string]any{
|
final := map[string]any{
|
||||||
|
|
@ -141,15 +109,15 @@ func registerCommiter(name, rpcURL string) error {
|
||||||
pub, priv, _ := ensureKeypair()
|
pub, priv, _ := ensureKeypair()
|
||||||
pubB64 := base64.StdEncoding.EncodeToString(pub)
|
pubB64 := base64.StdEncoding.EncodeToString(pub)
|
||||||
id := "commiter:" + pubB64
|
id := "commiter:" + pubB64
|
||||||
body := CommiterTxBody{
|
body := types.CommiterTxBody{
|
||||||
Type: "commiter",
|
Type: "commiter",
|
||||||
ID: id,
|
ID: id,
|
||||||
Name: name,
|
Name: name,
|
||||||
CommiterPubKey: pubB64, // ← ты думаешь, а на деле может быть иначе
|
CommiterPubKey: pubB64,
|
||||||
}
|
}
|
||||||
bodyBytes, _ := json.Marshal(body)
|
bodyBytes, _ := json.Marshal(body)
|
||||||
sig := ed25519.Sign(priv, bodyBytes)
|
sig := ed25519.Sign(priv, bodyBytes)
|
||||||
tx := SignedTx{Body: body, Signature: base64.StdEncoding.EncodeToString(sig)}
|
tx := types.SignedTx{Body: body, Signature: base64.StdEncoding.EncodeToString(sig)}
|
||||||
return sendTx(tx, rpcURL)
|
return sendTx(tx, rpcURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,13 +130,13 @@ func createPromise(desc, rpcURL string) error {
|
||||||
commitmentID := "commitment:" + uuid.NewString()
|
commitmentID := "commitment:" + uuid.NewString()
|
||||||
|
|
||||||
// Объекты тела
|
// Объекты тела
|
||||||
promise := &PromiseTxBody{
|
promise := &types.PromiseTxBody{
|
||||||
Type: "promise",
|
Type: "promise",
|
||||||
ID: promiseID,
|
ID: promiseID,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
commitment := &CommitmentTxBody{
|
commitment := &types.CommitmentTxBody{
|
||||||
Type: "commitment",
|
Type: "commitment",
|
||||||
ID: commitmentID,
|
ID: commitmentID,
|
||||||
PromiseID: promiseID,
|
PromiseID: promiseID,
|
||||||
|
|
@ -177,8 +145,8 @@ func createPromise(desc, rpcURL string) error {
|
||||||
|
|
||||||
// Сборка тела для подписи
|
// Сборка тела для подписи
|
||||||
bodyStruct := struct {
|
bodyStruct := struct {
|
||||||
Promise *PromiseTxBody `json:"promise"`
|
Promise *types.PromiseTxBody `json:"promise"`
|
||||||
Commitment *CommitmentTxBody `json:"commitment"`
|
Commitment *types.CommitmentTxBody `json:"commitment"`
|
||||||
}{
|
}{
|
||||||
Promise: promise,
|
Promise: promise,
|
||||||
Commitment: commitment,
|
Commitment: commitment,
|
||||||
|
|
@ -193,7 +161,7 @@ func createPromise(desc, rpcURL string) error {
|
||||||
sigB64 := base64.StdEncoding.EncodeToString(sig)
|
sigB64 := base64.StdEncoding.EncodeToString(sig)
|
||||||
|
|
||||||
// Формирование транзакции
|
// Формирование транзакции
|
||||||
compound := CompoundTx{
|
compound := types.CompoundTx{
|
||||||
Body: bodyStruct,
|
Body: bodyStruct,
|
||||||
Signature: sigB64,
|
Signature: sigB64,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue