Skip to content

Commit

Permalink
Merge pull request #142 from proximax-storage/develop
Browse files Browse the repository at this point in the history
Merge v0.8.4
  • Loading branch information
ynewmann authored Aug 30, 2024
2 parents 8fe6fd9 + 5cda7c0 commit eae4b19
Show file tree
Hide file tree
Showing 96 changed files with 3,348 additions and 8,939 deletions.
2 changes: 2 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3243,6 +3243,8 @@ const (
SecretProof EntityType = 0x4252
Transfer EntityType = 0x4154
ReplicatorOnboarding EntityType = 0x4662
ReplicatorsCleanup EntityType = 0x4062
ReplicatorTreeRebuild EntityType = 0x4167
PrepareBlockchainDrive EntityType = 0x4162
DataModification EntityType = 0x4262
DataModificationApproval EntityType = 0x4462
Expand Down
65 changes: 36 additions & 29 deletions examples/transactions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
panic(err)
}

ws, err := websocket.NewClient(ctx, conf)
ws, err := websocket.NewClient(conf)
if err != nil {
panic(err)
}
Expand All @@ -38,53 +38,59 @@ func main() {

customerAcc, err := client.NewAccount()
wg := new(sync.WaitGroup)
go ws.Listen()
go ws.Listen(ctx)

// The UnconfirmedAdded channel notifies when a transaction related to an
// address is in unconfirmed state and waiting to be included in a block.
// The message contains the transaction.

wg.Add(1)
err = ws.AddUnconfirmedAddedHandlers(customerAcc.Address, func(transaction sdk.Transaction) bool {
defer wg.Done()
fmt.Printf("UnconfirmedAdded Tx Content: %s \n", transaction.GetAbstractTransaction().TransactionHash)
return true
})

unconfSub, _, err := ws.NewUnConfirmedAddedSubscription(customerAcc.Address)
if err != nil {
panic(err)
}

wg.Add(1)
go func() {
defer wg.Done()

transaction := <-unconfSub
fmt.Printf("UnconfirmedAdded Tx Content: %s \n", transaction.GetAbstractTransaction().TransactionHash)
}()

//
//// The confirmedAdded channel notifies when a transaction related to an
//// address is included in a block. The message contains the transaction.

confSub, _, err := ws.NewConfirmedAddedSubscription(customerAcc.Address)
if err != nil {
panic(err)
}

wg.Add(1)
err = ws.AddConfirmedAddedHandlers(customerAcc.Address, func(transaction sdk.Transaction) bool {
go func() {
defer wg.Done()

transaction := <-confSub
fmt.Printf("ConfirmedAdded Tx Content: %s \n", transaction.GetAbstractTransaction().TransactionHash)
fmt.Println("Successful transfer!")
return true
})
}()

//The status channel notifies when a transaction related to an address rises an error.
//The message contains the error message and the transaction hash.

statusSub, _, err := ws.NewStatusSubscription(customerAcc.Address)
if err != nil {
panic(err)
}

//The status channel notifies when a transaction related to an address rises an error.
//The message contains the error message and the transaction hash.

wg.Add(1)
err = ws.AddStatusHandlers(customerAcc.Address, func(info *sdk.StatusInfo) bool {
go func() {
defer wg.Done()

info := <-statusSub
fmt.Printf("Content: %v \n", info.Hash)
panic(fmt.Sprint("Status: ", info.Status))
return true
})

if err != nil {
panic(err)
}
}()

time.Sleep(time.Second * 5)

Expand Down Expand Up @@ -135,17 +141,18 @@ func main() {
// The block channel notifies for every new block.
// The message contains the block information.

wg.Add(1)
err = ws.AddBlockHandlers(func(info *sdk.BlockInfo) bool {
defer wg.Done()
fmt.Printf("Block received with height: %v \n", info.Height)
return true
})

blockSub, _, err := ws.NewBlockSubscription()
if err != nil {
panic(err)
}

wg.Add(1)
go func() {
defer wg.Done()
info := <-blockSub
fmt.Printf("Block received with height: %v \n", info.Height)
}()

wg.Wait()

if err := ws.Close(); err != nil {
Expand Down
76 changes: 66 additions & 10 deletions examples/websocket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func main() {

client := sdk.NewClient(nil, cfg)

wsc, err := websocket.NewClient(ctx, cfg)
wsc, err := websocket.NewClient(cfg)
if err != nil {
panic(err)
}

//Starting listening messages from websocket
go wsc.Listen()
go wsc.Listen(ctx)

destAccount, _ := client.NewAccountFromPrivateKey(privateKey)
address := destAccount.PublicAccount.Address
Expand All @@ -48,38 +48,94 @@ func main() {

// Register handlers functions for needed topics

if err := wsc.AddBlockHandlers(BlocksHandler1, BlocksHandler2); err != nil {
subBlock, _, err := wsc.NewBlockSubscription()
if err != nil {
panic(err)
}

if err := wsc.AddConfirmedAddedHandlers(address, ConfirmedAddedHandler1, ConfirmedAddedHandler2); err != nil {
go func() {
block := <-subBlock
BlocksHandler1(block)
BlocksHandler2(block)
}()

subConfirmed, _, err := wsc.NewConfirmedAddedSubscription(address)
if err != nil {
panic(err)
}

if err := wsc.AddUnconfirmedAddedHandlers(address, UnconfirmedAddedHandler1, UnconfirmedAddedHandler2); err != nil {
go func() {
info := <-subConfirmed
ConfirmedAddedHandler1(info)
ConfirmedAddedHandler2(info)
}()

subUnconfirmed, _, err := wsc.NewUnConfirmedAddedSubscription(address)
if err != nil {
panic(err)
}

if err := wsc.AddUnconfirmedRemovedHandlers(address, UnconfirmedRemovedHandler1, UnconfirmedRemovedHandler2); err != nil {
go func() {
info := <-subUnconfirmed
UnconfirmedAddedHandler1(info)
UnconfirmedAddedHandler2(info)
}()

subUnconfirmedRemoved, _, err := wsc.NewUnConfirmedRemovedSubscription(address)
if err != nil {
panic(err)
}

if err := wsc.AddPartialAddedHandlers(address, PartialAddedHandler1, PartialAddedHandler2); err != nil {
go func() {
info := <-subUnconfirmedRemoved
UnconfirmedRemovedHandler1(info)
UnconfirmedRemovedHandler2(info)
}()

subPartial, _, err := wsc.NewPartialAddedSubscription(address)
if err != nil {
panic(err)
}

if err := wsc.AddPartialRemovedHandlers(address, PartialRemovedHandler1, PartialRemovedHandler2); err != nil {
go func() {
info := <-subPartial
PartialAddedHandler1(info)
PartialAddedHandler2(info)
}()

subPartialRemoved, _, err := wsc.NewPartialRemovedSubscription(address)
if err != nil {
panic(err)
}

if err := wsc.AddStatusHandlers(address, StatusHandler1, StatusHandler2); err != nil {
go func() {
info := <-subPartialRemoved
PartialRemovedHandler1(info)
PartialRemovedHandler2(info)
}()

subStatus, _, err := wsc.NewStatusSubscription(address)
if err != nil {
panic(err)
}

if err := wsc.AddCosignatureHandlers(address, CosignatureHandler1, CosignatureHandler2); err != nil {
go func() {
info := <-subStatus
StatusHandler1(info)
StatusHandler2(info)
}()

subCosignature, _, err := wsc.NewCosignatureSubscription(address)
if err != nil {
panic(err)
}

go func() {
info := <-subCosignature
CosignatureHandler1(info)
CosignatureHandler2(info)
}()

//Running the goroutine which will close websocket connection and listening after 2 minutes.
go func() {
timer := time.NewTimer(time.Minute * 2)
Expand Down
25 changes: 19 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
module github.com/proximax-storage/go-xpx-chain-sdk

go 1.13
go 1.18

require (
github.com/google/flatbuffers v1.11.0
github.com/google/go-querystring v1.0.0
github.com/gorilla/websocket v1.4.0
github.com/json-iterator/go v1.1.6
github.com/gorilla/websocket v1.5.1
github.com/json-iterator/go v1.1.12
github.com/pkg/errors v0.8.1
github.com/proximax-storage/go-xpx-chain-sync v1.1.2
github.com/proximax-storage/go-xpx-chain-sync v1.1.4-0.20240304152714-531033efe0a3
github.com/proximax-storage/go-xpx-crypto v0.0.0-20191023142918-e02e2652d78e
github.com/proximax-storage/go-xpx-utils v0.0.0-20190604083640-90d06ff8a19f
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.8.1
github.com/supranational/blst v0.3.2
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
golang.org/x/crypto v0.14.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit eae4b19

Please sign in to comment.