Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Bitcoin Checkpointing MVP #83

Draft
wants to merge 23 commits into
base: eudico
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ bin/ipget
bin/tmp/*
.idea
scratchpad

gen.gen
*.key
data/*/*
!data/*/keystore/
!data/*/config.toml
!data/*/token
!data/*/share.toml
7 changes: 7 additions & 0 deletions chain/checkpointing/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package checkpointing

var FEE float64 = 0.01
var S3_HOST string = "minio.deadbrain.corp"
var ACCESS_KEY_ID string = ""
var SECRET_ACCESS_KEY string = ""
var BUCKET_NAME string = "eudico"
rllola marked this conversation as resolved.
Show resolved Hide resolved
61 changes: 61 additions & 0 deletions chain/checkpointing/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package checkpointing

import (
"context"
"fmt"

"github.com/Zondax/multi-party-sig/pkg/party"
"github.com/Zondax/multi-party-sig/pkg/protocol"
pubsub "github.com/libp2p/go-libp2p-pubsub"
)

type Network struct {
sub *pubsub.Subscription
topic *pubsub.Topic
parties party.IDSlice
}

func NewNetwork(parties party.IDSlice, sub *pubsub.Subscription, topic *pubsub.Topic) *Network {
c := &Network{
sub: sub,
topic: topic,
parties: parties,
}
return c
}

func (n *Network) Next(ctx context.Context) *protocol.Message {
msg, err := n.sub.Next(ctx)
if err != nil {
panic(err)
}

// Converting a pubsub.Message into a protocol.Message
rllola marked this conversation as resolved.
Show resolved Hide resolved
// see https://pkg.go.dev/github.com/libp2p/[email protected]/pb#Message
// https://pkg.go.dev/github.com/taurusgroup/[email protected]/pkg/protocol?utm_source=gopls#Message
var pmessage protocol.Message
err = pmessage.UnmarshalBinary(msg.Data)
if err != nil {
panic(err)
}

return &pmessage
}

func (n *Network) Send(ctx context.Context, msg *protocol.Message) {
data, err := msg.MarshalBinary()
if err != nil {
panic(err)
}
n.topic.Publish(ctx, data)
}

func (n *Network) Done() {
fmt.Println("Done")

/* Might need to do something here ? */
}

func (n *Network) Parties() party.IDSlice {
return n.parties
}
36 changes: 36 additions & 0 deletions chain/checkpointing/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package checkpointing

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"os"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)

func StoreConfig() {
// Initialize minio client object.
minioClient, err := minio.New(S3_HOST, &minio.Options{
Creds: credentials.NewStaticV4(ACCESS_KEY_ID, SECRET_ACCESS_KEY, ""),
Secure: false,
})
rllola marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
panic(err)
}

fmt.Println(minioClient)
rllola marked this conversation as resolved.
Show resolved Hide resolved
}

func CreateConfig(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)

fmt.Println(hex.EncodeToString(hash[:]))
err := os.WriteFile("/tmp/"+hex.EncodeToString(hash[:]), data, 0644)
if err != nil {
return nil, err
}

return hash[:], nil
}
Loading