From ee7e1edc87fba5385f6fec4f25119d4f88479ac7 Mon Sep 17 00:00:00 2001 From: slackve Date: Thu, 11 Oct 2018 20:38:22 -0400 Subject: [PATCH 1/9] Modification of GetMosaic method --- sdk/mosaic.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/mosaic.go b/sdk/mosaic.go index 101c43a..3c40191 100644 --- a/sdk/mosaic.go +++ b/sdk/mosaic.go @@ -16,7 +16,7 @@ type MosaicService service // mosaics get mosaics Info // @get /mosaic/{mosaicId} -func (ref *MosaicService) GetMosaic(ctx context.Context, mosaicId MosaicId) (mscInfo *MosaicInfo, resp *http.Response, err error) { +func (ref *MosaicService) GetMosaic(ctx context.Context, mosaicId *MosaicId) (mscInfo *MosaicInfo, resp *http.Response, err error) { mscInfoDTO := &mosaicInfoDTO{} resp, err = ref.client.DoNewRequest(ctx, "GET", pathMosaic+mosaicId.toHexString(), nil, mscInfoDTO) @@ -80,7 +80,6 @@ func (ref *MosaicService) GetMosaicNames(ctx context.Context, mosaicIds MosaicId } // GetMosaicsFromNamespace Get mosaics information from namespaceId (nsId) -// get @/namespaces/{namespaceId}/mosaic/ func (ref *MosaicService) GetMosaicsFromNamespace(ctx context.Context, namespaceId *NamespaceId, mosaicId *MosaicId, pageSize int) (mscInfo []*MosaicInfo, resp *http.Response, err error) { From 81d20fcf74a898d4ebffdb1586803fa4161d4e79 Mon Sep 17 00:00:00 2001 From: slackve Date: Thu, 11 Oct 2018 20:41:20 -0400 Subject: [PATCH 2/9] Change ListNamespaceInfo from private to public (list) --- sdk/namespace.go | 2 +- sdk/namespace_model.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/namespace.go b/sdk/namespace.go index 69efb41..c2e116d 100644 --- a/sdk/namespace.go +++ b/sdk/namespace.go @@ -236,7 +236,7 @@ func listNamespaceInfoFromDTO(res []*namespaceInfoDTO, nsList *ListNamespaceInfo if err != nil { return err } - nsList.list = append(nsList.list, nsInfo) + nsList.List = append(nsList.List, nsInfo) } return nil diff --git a/sdk/namespace_model.go b/sdk/namespace_model.go index 70ec441..34ee95d 100644 --- a/sdk/namespace_model.go +++ b/sdk/namespace_model.go @@ -139,7 +139,7 @@ func (ref *NamespaceInfo) String() string { // ListNamespaceInfo is a list NamespaceInfo type ListNamespaceInfo struct { - list []*NamespaceInfo + List []*NamespaceInfo } // generateNamespaceId create NamespaceId from namespace string name (ex: nem or domain.subdom.subdome) From 3df2be344c80ee043bdcea1cf7eb6333e4a7fd7c Mon Sep 17 00:00:00 2001 From: slackve Date: Fri, 12 Oct 2018 23:25:31 -0400 Subject: [PATCH 3/9] Refactor websocket client design --- examples/websocket/main.go | 45 ++++++------- sdk/subscribe_block.go | 91 ++++++++++++++++++++------ sdk/websocket.go | 128 +++++++++++++++++++++++++++---------- 3 files changed, 187 insertions(+), 77 deletions(-) diff --git a/examples/websocket/main.go b/examples/websocket/main.go index eff1969..e608af1 100644 --- a/examples/websocket/main.go +++ b/examples/websocket/main.go @@ -38,45 +38,41 @@ func main() { // 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. - a, _ := ws.Subscribe.UnconfirmedAdded(acc.Address.Address) + chUnconfirmedAdded, _ := ws.Subscribe.UnconfirmedAdded(acc.Address.Address) go func() { for { - data := <-a.ChIn - ch := data.(sdk.Transaction) - fmt.Printf("UnconfirmedAdded Tx Hash: %v \n", ch.GetAbstractTransaction().Hash) - a.Unsubscribe() + data := <-chUnconfirmedAdded.Ch + fmt.Printf("UnconfirmedAdded Tx Hash: %v \n", data.GetAbstractTransaction().Hash) + chUnconfirmedAdded.Unsubscribe() } }() - - // The confirmedAdded channel notifies when a transaction related to an - // address is included in a block. The message contains the transaction. - b, _ := ws.Subscribe.ConfirmedAdded(acc.Address.Address) + // + //// The confirmedAdded channel notifies when a transaction related to an + //// address is included in a block. The message contains the transaction. + chConfirmedAdded, _ := ws.Subscribe.ConfirmedAdded(acc.Address.Address) go func() { for { - data := <-b.ChIn - ch := data.(sdk.Transaction) - fmt.Printf("ConfirmedAdded Tx Hash: %v \n", ch.GetAbstractTransaction().Hash) - b.Unsubscribe() + data := <-chConfirmedAdded.Ch + fmt.Printf("ConfirmedAdded Tx Hash: %v \n", data.GetAbstractTransaction().Hash) + chConfirmedAdded.Unsubscribe() fmt.Println("Successful transfer!") - } }() //The status channel notifies when a transaction related to an address rises an error. //The message contains the error message and the transaction hash. - c, _ := ws.Subscribe.Status(acc.Address.Address) + chStatus, _ := ws.Subscribe.Status(acc.Address.Address) go func() { for { - data := <-c.ChIn - ch := data.(sdk.StatusInfo) - c.Unsubscribe() - fmt.Printf("Hash: %v \n", ch.Hash) - panic(fmt.Sprint("Status: ", ch.Status)) + data := <-chStatus.Ch + chStatus.Unsubscribe() + fmt.Printf("Hash: %v \n", data.Hash) + panic(fmt.Sprint("Status: ", data.Status)) } }() - time.Sleep(time.Second * 5) + //time.Sleep(time.Second * 5) // Use the default http client client := sdk.NewClient(nil, conf) @@ -105,11 +101,10 @@ func main() { // The block channel notifies for every new block. // The message contains the block information. - d, _ := ws.Subscribe.Block() + chBlock, _ := ws.Subscribe.Block() for { - data := <-d.ChIn - ch := data.(*sdk.BlockInfo) - fmt.Printf("Block received with height: %v \n", ch.Height) + data := <-chBlock.Ch + fmt.Printf("Block received with height: %v \n", data.Height) } } diff --git a/sdk/subscribe_block.go b/sdk/subscribe_block.go index 99e60a9..5ea426d 100644 --- a/sdk/subscribe_block.go +++ b/sdk/subscribe_block.go @@ -6,13 +6,24 @@ package sdk import "golang.org/x/net/websocket" +var ChSubscribe struct { + Block *SubscribeBlock + ConfirmedAdded *SubscribeTransaction + UnconfirmedAdded *SubscribeTransaction + UnconfirmedRemoved *SubscribeHash + Status *SubscribeStatus + PartialAdded *SubscribeTransaction + PartialRemoved *SubscribePartialRemoved + Cosignature *SubscribeSigner +} + // structure for Subscribe status -type SubscribeHash struct { +type HashInfo struct { Hash string `json:"hash"` } // structure for Subscribe PartialRemoved -type SubscribePartialRemoved struct { +type PartialRemovedInfo struct { Meta SubscribeHash `json:"meta"` } @@ -32,61 +43,101 @@ const ( // Block notifies for every new block. // The message contains the BlockInfo struct. -func (c *SubscribeService) Block() (*Subscribe, error) { - return c.newChannel(pathBlock) +func (c *SubscribeService) Block() (*SubscribeBlock, error) { + subBlock := new(SubscribeBlock) + ChSubscribe.Block = subBlock + subBlock.Ch = make(chan *BlockInfo) + subscribe, err := c.newSubscribe(pathBlock) + subBlock.subscribe = subscribe + return subBlock, err } // ConfirmedAdded notifies when a transaction related to an // address is included in a block. // The message contains the transaction. -func (c *SubscribeService) ConfirmedAdded(add string) (*Subscribe, error) { - return c.newChannel(pathConfirmedAdded + "/" + add) +func (c *SubscribeService) ConfirmedAdded(add string) (*SubscribeTransaction, error) { + subTransaction := new(SubscribeTransaction) + ChSubscribe.ConfirmedAdded = subTransaction + subTransaction.Ch = make(chan Transaction) + subscribe, err := c.newSubscribe(pathConfirmedAdded + "/" + add) + subTransaction.subscribe = subscribe + return subTransaction, err } // UnconfirmedAdded 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. -func (c *SubscribeService) UnconfirmedAdded(add string) (*Subscribe, error) { - return c.newChannel(pathUnconfirmedAdded + "/" + add) +func (c *SubscribeService) UnconfirmedAdded(add string) (*SubscribeTransaction, error) { + subTransaction := new(SubscribeTransaction) + ChSubscribe.UnconfirmedAdded = subTransaction + subTransaction.Ch = make(chan Transaction) + subscribe, err := c.newSubscribe(pathUnconfirmedAdded + "/" + add) + subTransaction.subscribe = subscribe + return subTransaction, err } // UnconfirmedRemoved notifies when a transaction related to an // address was in unconfirmed state but not anymore. // The message contains the transaction hash. -func (c *SubscribeService) UnconfirmedRemoved(add string) (*Subscribe, error) { - return c.newChannel(pathUnconfirmedRemoved + "/" + add) +func (c *SubscribeService) UnconfirmedRemoved(add string) (*SubscribeHash, error) { + subHash := new(SubscribeHash) + ChSubscribe.UnconfirmedRemoved = subHash + subHash.Ch = make(chan *HashInfo) + subscribe, err := c.newSubscribe(pathUnconfirmedRemoved + "/" + add) + subHash.subscribe = subscribe + return subHash, err } // Status notifies when a transaction related to an address rises an error. // The message contains the error message and the transaction hash. -func (c *SubscribeService) Status(add string) (*Subscribe, error) { - return c.newChannel(pathStatus + "/" + add) +func (c *SubscribeService) Status(add string) (*SubscribeStatus, error) { + subStatus := new(SubscribeStatus) + ChSubscribe.Status = subStatus + subStatus.Ch = make(chan *StatusInfo) + subscribe, err := c.newSubscribe(pathStatus + "/" + add) + subStatus.subscribe = subscribe + return subStatus, err } // PartialAdded notifies when an aggregate bonded transaction related to an // address is in partial state and waiting to have all required cosigners. // The message contains a transaction. -func (c *SubscribeService) PartialAdded(add string) (*Subscribe, error) { - return c.newChannel(pathPartialAdded + "/" + add) +func (c *SubscribeService) PartialAdded(add string) (*SubscribeTransaction, error) { + subTransaction := new(SubscribeTransaction) + ChSubscribe.PartialAdded = subTransaction + subTransaction.Ch = make(chan Transaction) + subscribe, err := c.newSubscribe(pathPartialAdded + "/" + add) + subTransaction.subscribe = subscribe + return subTransaction, err } // PartialRemoved notifies when a transaction related to an // address was in partial state but not anymore. // The message contains the transaction hash. -func (c *SubscribeService) PartialRemoved(add string) (*Subscribe, error) { - return c.newChannel(pathPartialRemoved + "/" + add) +func (c *SubscribeService) PartialRemoved(add string) (*SubscribePartialRemoved, error) { + subPartialRemoved := new(SubscribePartialRemoved) + ChSubscribe.PartialRemoved = subPartialRemoved + subPartialRemoved.Ch = make(chan *PartialRemovedInfo) + subscribe, err := c.newSubscribe(pathPartialRemoved + "/" + add) + subPartialRemoved.subscribe = subscribe + return ChSubscribe.PartialRemoved, err } // Cosignature notifies when a cosignature signed transaction related to an // address is added to an aggregate bonded transaction with partial state. // The message contains the cosignature signed transaction. -func (c *SubscribeService) Cosignature(add string) (*Subscribe, error) { - return c.newChannel(pathCosignature + "/" + add) +func (c *SubscribeService) Cosignature(add string) (*SubscribeSigner, error) { + subCosignature := new(SubscribeSigner) + ChSubscribe.Cosignature = subCosignature + subCosignature.Ch = make(chan *SignerInfo) + subscribe, err := c.newSubscribe(pathCosignature + "/" + add) + subCosignature.subscribe = subscribe + return ChSubscribe.Cosignature, err } // Unsubscribe terminates the specified subscription. // It does not have any specific param. -func (c *Subscribe) Unsubscribe() error { +func (c *subscribe) unsubscribe() error { if err := websocket.JSON.Send(c.conn, sendJson{ Uid: c.Uid, Subscribe: c.Subscribe, @@ -99,7 +150,7 @@ func (c *Subscribe) Unsubscribe() error { // Generate a new channel and subscribe to the websocket. // param route A subscription channel route. // return A pointer Subscribe struct or an error. -func (c *SubscribeService) newChannel(route string) (*Subscribe, error) { +func (c *SubscribeService) newSubscribe(route string) (*subscribe, error) { subMsg := c.client.buildSubscribe(route) err := c.client.subsChannel(subMsg) diff --git a/sdk/websocket.go b/sdk/websocket.go index 9b5f0ac..f547989 100644 --- a/sdk/websocket.go +++ b/sdk/websocket.go @@ -19,28 +19,76 @@ type serviceWs struct { client *ClientWs } -var chanSubscribe = struct { - block chan BlockInfo - status chan StatusInfo -}{} - // Catapult Websocket Client configuration type ClientWs struct { - client *websocket.Conn - Uid string - config *Config - common serviceWs // Reuse a single struct instead of allocating one for each service on the heap. - Subscribe *SubscribeService - subscriptions map[string]chan<- interface{} + client *websocket.Conn + Uid string + config *Config + common serviceWs // Reuse a single struct instead of allocating one for each service on the heap. + Subscribe *SubscribeService + //subscriptions map[string]chan<- interface{} } -type Subscribe struct { +type subscribe struct { Uid string `json:"uid"` Subscribe string `json:"subscribe"` - ChIn chan interface{} conn *websocket.Conn } +type SubscribeBlock struct { + *subscribe + Ch chan *BlockInfo +} + +func (s *SubscribeBlock) Unsubscribe() error { + return s.subscribe.unsubscribe() +} + +type SubscribeTransaction struct { + *subscribe + Ch chan Transaction +} + +func (s *SubscribeTransaction) Unsubscribe() error { + return s.subscribe.unsubscribe() +} + +type SubscribeHash struct { + *subscribe + Ch chan *HashInfo +} + +func (s *SubscribeHash) Unsubscribe() error { + return s.subscribe.unsubscribe() +} + +type SubscribePartialRemoved struct { + *subscribe + Ch chan *PartialRemovedInfo +} + +func (s *SubscribePartialRemoved) Unsubscribe() error { + return s.subscribe.unsubscribe() +} + +type SubscribeStatus struct { + *subscribe + Ch chan *StatusInfo +} + +func (s *SubscribeStatus) Unsubscribe() error { + return s.subscribe.unsubscribe() +} + +type SubscribeSigner struct { + *subscribe + Ch chan *SignerInfo +} + +func (s *SubscribeSigner) Unsubscribe() error { + return s.subscribe.unsubscribe() +} + type sendJson struct { Uid string `json:"uid"` Subscribe string `json:"subscribe"` @@ -63,7 +111,7 @@ func NewConnectWs(host string) (*ClientWs, error) { c := &ClientWs{config: newconf} c.common.client = c c.Subscribe = (*SubscribeService)(&c.common) - c.subscriptions = make(map[string]chan<- interface{}) + //c.subscriptions = make(map[string]chan<- interface{}) err = c.wsConnect() if err != nil { @@ -72,11 +120,11 @@ func NewConnectWs(host string) (*ClientWs, error) { return c, nil } -func (c *ClientWs) buildSubscribe(destination string) *Subscribe { - b := new(Subscribe) - b.ChIn = make(chan interface{}) - subName := strings.Split(destination, "/")[0] - c.subscriptions[subName] = b.ChIn +func (c *ClientWs) buildSubscribe(destination string) *subscribe { + b := new(subscribe) + //b.ChIn = make(chan interface{}) + //subName := strings.Split(destination, "/")[0] + //c.subscriptions[subName] = b.ChIn b.Uid = c.Uid b.Subscribe = destination b.conn = c.client @@ -109,7 +157,7 @@ func (c *ClientWs) wsConnect() error { return nil } -func (c *ClientWs) subsChannel(msg *Subscribe) error { +func (c *ClientWs) subsChannel(msg *subscribe) error { if err := websocket.JSON.Send(c.client, sendJson{ Uid: msg.Uid, Subscribe: msg.Subscribe, @@ -147,8 +195,8 @@ func (c *ClientWs) subsChannel(msg *Subscribe) error { return e } -func msgParser(msg []byte) (*Subscribe, error) { - var message Subscribe +func msgParser(msg []byte) (*subscribe, error) { + var message subscribe err := json.Unmarshal(msg, &message) if err != nil { return nil, err @@ -199,7 +247,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - c.subscriptions[name] <- data + ChSubscribe.Block.Ch <- data return nil case "status": @@ -208,34 +256,50 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - c.subscriptions[name] <- data + ChSubscribe.Status.Ch <- &data return nil case "signer": var data SignerInfo - err := json.Unmarshal(t, &data) + err := json.Unmarshal(t, data) if err != nil { return err } - c.subscriptions["cosignature"] <- data + ChSubscribe.Cosignature.Ch <- &data return nil case "unconfirmedRemoved": - var data SubscribeHash - err := json.Unmarshal(t, &data) + var data HashInfo + err := json.Unmarshal(t, data) if err != nil { return err } - c.subscriptions[name] <- data + ChSubscribe.UnconfirmedRemoved.Ch <- &data return nil case "partialRemoved": - var data SubscribePartialRemoved + var data PartialRemovedInfo err := json.Unmarshal(t, &data) if err != nil { return err } - c.subscriptions[name] <- data + ChSubscribe.PartialRemoved.Ch <- &data + return nil + + case "partialAdded": + data, err := MapTransaction(bytes.NewBuffer([]byte(t))) + if err != nil { + return err + } + ChSubscribe.UnconfirmedAdded.Ch <- data + return nil + + case "unconfirmedAdded": + data, err := MapTransaction(bytes.NewBuffer([]byte(t))) + if err != nil { + return err + } + ChSubscribe.UnconfirmedAdded.Ch <- data return nil default: @@ -243,7 +307,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - c.subscriptions[name] <- data + ChSubscribe.ConfirmedAdded.Ch <- data return nil } } From 3e614a88422b1429a8c55087d1a7661f73f403bd Mon Sep 17 00:00:00 2001 From: slackve Date: Fri, 12 Oct 2018 23:51:55 -0400 Subject: [PATCH 4/9] remove comment --- sdk/websocket.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sdk/websocket.go b/sdk/websocket.go index f547989..bef9132 100644 --- a/sdk/websocket.go +++ b/sdk/websocket.go @@ -26,7 +26,6 @@ type ClientWs struct { config *Config common serviceWs // Reuse a single struct instead of allocating one for each service on the heap. Subscribe *SubscribeService - //subscriptions map[string]chan<- interface{} } type subscribe struct { @@ -111,7 +110,6 @@ func NewConnectWs(host string) (*ClientWs, error) { c := &ClientWs{config: newconf} c.common.client = c c.Subscribe = (*SubscribeService)(&c.common) - //c.subscriptions = make(map[string]chan<- interface{}) err = c.wsConnect() if err != nil { @@ -122,9 +120,6 @@ func NewConnectWs(host string) (*ClientWs, error) { func (c *ClientWs) buildSubscribe(destination string) *subscribe { b := new(subscribe) - //b.ChIn = make(chan interface{}) - //subName := strings.Split(destination, "/")[0] - //c.subscriptions[subName] = b.ChIn b.Uid = c.Uid b.Subscribe = destination b.conn = c.client From c0c0468799461e20647195e4d7c2647bc56821b6 Mon Sep 17 00:00:00 2001 From: slackve Date: Sat, 13 Oct 2018 18:18:36 -0400 Subject: [PATCH 5/9] rename ChSubscribe to ChanSubscribe --- sdk/subscribe_block.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/subscribe_block.go b/sdk/subscribe_block.go index 5ea426d..16050e7 100644 --- a/sdk/subscribe_block.go +++ b/sdk/subscribe_block.go @@ -6,7 +6,7 @@ package sdk import "golang.org/x/net/websocket" -var ChSubscribe struct { +var ChanSubscribe struct { Block *SubscribeBlock ConfirmedAdded *SubscribeTransaction UnconfirmedAdded *SubscribeTransaction @@ -45,7 +45,7 @@ const ( // The message contains the BlockInfo struct. func (c *SubscribeService) Block() (*SubscribeBlock, error) { subBlock := new(SubscribeBlock) - ChSubscribe.Block = subBlock + ChanSubscribe.Block = subBlock subBlock.Ch = make(chan *BlockInfo) subscribe, err := c.newSubscribe(pathBlock) subBlock.subscribe = subscribe @@ -57,7 +57,7 @@ func (c *SubscribeService) Block() (*SubscribeBlock, error) { // The message contains the transaction. func (c *SubscribeService) ConfirmedAdded(add string) (*SubscribeTransaction, error) { subTransaction := new(SubscribeTransaction) - ChSubscribe.ConfirmedAdded = subTransaction + ChanSubscribe.ConfirmedAdded = subTransaction subTransaction.Ch = make(chan Transaction) subscribe, err := c.newSubscribe(pathConfirmedAdded + "/" + add) subTransaction.subscribe = subscribe @@ -69,7 +69,7 @@ func (c *SubscribeService) ConfirmedAdded(add string) (*SubscribeTransaction, er // The message contains the transaction. func (c *SubscribeService) UnconfirmedAdded(add string) (*SubscribeTransaction, error) { subTransaction := new(SubscribeTransaction) - ChSubscribe.UnconfirmedAdded = subTransaction + ChanSubscribe.UnconfirmedAdded = subTransaction subTransaction.Ch = make(chan Transaction) subscribe, err := c.newSubscribe(pathUnconfirmedAdded + "/" + add) subTransaction.subscribe = subscribe @@ -81,7 +81,7 @@ func (c *SubscribeService) UnconfirmedAdded(add string) (*SubscribeTransaction, // The message contains the transaction hash. func (c *SubscribeService) UnconfirmedRemoved(add string) (*SubscribeHash, error) { subHash := new(SubscribeHash) - ChSubscribe.UnconfirmedRemoved = subHash + ChanSubscribe.UnconfirmedRemoved = subHash subHash.Ch = make(chan *HashInfo) subscribe, err := c.newSubscribe(pathUnconfirmedRemoved + "/" + add) subHash.subscribe = subscribe @@ -92,7 +92,7 @@ func (c *SubscribeService) UnconfirmedRemoved(add string) (*SubscribeHash, error // The message contains the error message and the transaction hash. func (c *SubscribeService) Status(add string) (*SubscribeStatus, error) { subStatus := new(SubscribeStatus) - ChSubscribe.Status = subStatus + ChanSubscribe.Status = subStatus subStatus.Ch = make(chan *StatusInfo) subscribe, err := c.newSubscribe(pathStatus + "/" + add) subStatus.subscribe = subscribe @@ -104,7 +104,7 @@ func (c *SubscribeService) Status(add string) (*SubscribeStatus, error) { // The message contains a transaction. func (c *SubscribeService) PartialAdded(add string) (*SubscribeTransaction, error) { subTransaction := new(SubscribeTransaction) - ChSubscribe.PartialAdded = subTransaction + ChanSubscribe.PartialAdded = subTransaction subTransaction.Ch = make(chan Transaction) subscribe, err := c.newSubscribe(pathPartialAdded + "/" + add) subTransaction.subscribe = subscribe @@ -116,11 +116,11 @@ func (c *SubscribeService) PartialAdded(add string) (*SubscribeTransaction, erro // The message contains the transaction hash. func (c *SubscribeService) PartialRemoved(add string) (*SubscribePartialRemoved, error) { subPartialRemoved := new(SubscribePartialRemoved) - ChSubscribe.PartialRemoved = subPartialRemoved + ChanSubscribe.PartialRemoved = subPartialRemoved subPartialRemoved.Ch = make(chan *PartialRemovedInfo) subscribe, err := c.newSubscribe(pathPartialRemoved + "/" + add) subPartialRemoved.subscribe = subscribe - return ChSubscribe.PartialRemoved, err + return ChanSubscribe.PartialRemoved, err } // Cosignature notifies when a cosignature signed transaction related to an @@ -128,11 +128,11 @@ func (c *SubscribeService) PartialRemoved(add string) (*SubscribePartialRemoved, // The message contains the cosignature signed transaction. func (c *SubscribeService) Cosignature(add string) (*SubscribeSigner, error) { subCosignature := new(SubscribeSigner) - ChSubscribe.Cosignature = subCosignature + ChanSubscribe.Cosignature = subCosignature subCosignature.Ch = make(chan *SignerInfo) subscribe, err := c.newSubscribe(pathCosignature + "/" + add) subCosignature.subscribe = subscribe - return ChSubscribe.Cosignature, err + return ChanSubscribe.Cosignature, err } // Unsubscribe terminates the specified subscription. From 6a7e2a3652f45ce6fbe6868d98dc739cb5a1f86d Mon Sep 17 00:00:00 2001 From: slackve Date: Sat, 13 Oct 2018 18:19:03 -0400 Subject: [PATCH 6/9] rename ClientWs to ClientWebsocket --- sdk/websocket.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/sdk/websocket.go b/sdk/websocket.go index bef9132..687f8ad 100644 --- a/sdk/websocket.go +++ b/sdk/websocket.go @@ -16,11 +16,11 @@ import ( ) type serviceWs struct { - client *ClientWs + client *ClientWebsocket } // Catapult Websocket Client configuration -type ClientWs struct { +type ClientWebsocket struct { client *websocket.Conn Uid string config *Config @@ -93,7 +93,7 @@ type sendJson struct { Subscribe string `json:"subscribe"` } -func (c *ClientWs) changeURLPort() { +func (c *ClientWebsocket) changeURLPort() { c.config.BaseURL.Scheme = "ws" c.config.BaseURL.Path = "/ws" split := strings.Split(c.config.BaseURL.Host, ":") @@ -101,13 +101,13 @@ func (c *ClientWs) changeURLPort() { c.config.BaseURL.Host = strings.Join([]string{host, port}, ":") } -func NewConnectWs(host string) (*ClientWs, error) { +func NewConnectWs(host string) (*ClientWebsocket, error) { u, err := url.Parse(host) if err != nil { return nil, err } newconf := &Config{BaseURL: u} - c := &ClientWs{config: newconf} + c := &ClientWebsocket{config: newconf} c.common.client = c c.Subscribe = (*SubscribeService)(&c.common) @@ -118,7 +118,7 @@ func NewConnectWs(host string) (*ClientWs, error) { return c, nil } -func (c *ClientWs) buildSubscribe(destination string) *subscribe { +func (c *ClientWebsocket) buildSubscribe(destination string) *subscribe { b := new(subscribe) b.Uid = c.Uid b.Subscribe = destination @@ -126,7 +126,7 @@ func (c *ClientWs) buildSubscribe(destination string) *subscribe { return b } -func (c *ClientWs) wsConnect() error { +func (c *ClientWebsocket) wsConnect() error { c.changeURLPort() conn, err := websocket.Dial(c.config.BaseURL.String(), "", "http://localhost") if err != nil { @@ -152,7 +152,7 @@ func (c *ClientWs) wsConnect() error { return nil } -func (c *ClientWs) subsChannel(msg *subscribe) error { +func (c *ClientWebsocket) subsChannel(msg *subscribe) error { if err := websocket.JSON.Send(c.client, sendJson{ Uid: msg.Uid, Subscribe: msg.Subscribe, @@ -230,7 +230,7 @@ func restParser(data []byte) (string, error) { return subscribe, nil } -func (c *ClientWs) buildType(name string, t []byte) error { +func (c *ClientWebsocket) buildType(name string, t []byte) error { switch name { case "block": var b blockInfoDTO @@ -242,7 +242,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.Block.Ch <- data + ChanSubscribe.Block.Ch <- data return nil case "status": @@ -251,7 +251,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.Status.Ch <- &data + ChanSubscribe.Status.Ch <- &data return nil case "signer": @@ -260,7 +260,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.Cosignature.Ch <- &data + ChanSubscribe.Cosignature.Ch <- &data return nil case "unconfirmedRemoved": @@ -269,7 +269,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.UnconfirmedRemoved.Ch <- &data + ChanSubscribe.UnconfirmedRemoved.Ch <- &data return nil case "partialRemoved": @@ -278,7 +278,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.PartialRemoved.Ch <- &data + ChanSubscribe.PartialRemoved.Ch <- &data return nil case "partialAdded": @@ -286,7 +286,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.UnconfirmedAdded.Ch <- data + ChanSubscribe.UnconfirmedAdded.Ch <- data return nil case "unconfirmedAdded": @@ -294,7 +294,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.UnconfirmedAdded.Ch <- data + ChanSubscribe.UnconfirmedAdded.Ch <- data return nil default: @@ -302,7 +302,7 @@ func (c *ClientWs) buildType(name string, t []byte) error { if err != nil { return err } - ChSubscribe.ConfirmedAdded.Ch <- data + ChanSubscribe.ConfirmedAdded.Ch <- data return nil } } From 26128da2472693449df2994d2c8dbb0141c2ad57 Mon Sep 17 00:00:00 2001 From: slackve Date: Sat, 13 Oct 2018 18:20:55 -0400 Subject: [PATCH 7/9] remove comment --- examples/websocket/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/websocket/main.go b/examples/websocket/main.go index e608af1..7379a86 100644 --- a/examples/websocket/main.go +++ b/examples/websocket/main.go @@ -12,7 +12,7 @@ import ( ) const ( - baseUrl = "http://localhost:3000" + baseUrl = "http://vpn.isarq.com:3000" networkType = sdk.MijinTest privateKey = "0F3CC33190A49ABB32E7172E348EA927F975F8829107AAA3D6349BB10797D4F6" ) @@ -72,7 +72,7 @@ func main() { } }() - //time.Sleep(time.Second * 5) + time.Sleep(time.Second * 5) // Use the default http client client := sdk.NewClient(nil, conf) From 6b6ce72ca86f6f34aac11e7ced21d244e72bfe3e Mon Sep 17 00:00:00 2001 From: slackve Date: Sat, 13 Oct 2018 18:22:36 -0400 Subject: [PATCH 8/9] add localhost to baseUrl --- examples/websocket/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/websocket/main.go b/examples/websocket/main.go index 7379a86..58fd683 100644 --- a/examples/websocket/main.go +++ b/examples/websocket/main.go @@ -12,7 +12,7 @@ import ( ) const ( - baseUrl = "http://vpn.isarq.com:3000" + baseUrl = "http://localhost:3000" networkType = sdk.MijinTest privateKey = "0F3CC33190A49ABB32E7172E348EA927F975F8829107AAA3D6349BB10797D4F6" ) From af849dbe46858a607a2fa41c97a9facd98313e5b Mon Sep 17 00:00:00 2001 From: BramBear Date: Sat, 13 Oct 2018 22:46:23 -0400 Subject: [PATCH 9/9] Added keypair generator with pvkey #80 Remove dependencies on testnet/mainnet specific config #77 --- README.md | 4 ++-- crypto/key_model.go | 4 ++-- examples/blockchain_api/main.go | 7 +++++-- examples/websocket/main.go | 4 ++-- sdk/account.go | 2 ++ sdk/account_model.go | 25 +++++++++++++++++++------ sdk/account_model_test.go | 12 ++++++++++++ sdk/blockchain_model.go | 2 +- sdk/blockchain_test.go | 2 +- sdk/mosaic.go | 2 +- sdk/mosaic_test.go | 11 +++-------- sdk/namespace.go | 2 +- sdk/namespace_test.go | 8 ++++---- sdk/sdk_model.go | 2 +- sdk/transaction_model.go | 6 +++--- sdk/transaction_test.go | 30 +++++++++++++++--------------- 16 files changed, 74 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 8532543..c5f02ca 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,11 @@ Create a Catapult network configuration Using the *Testnet* network ```go -conf, err := sdk.LoadTestnetConfig("http://localhost:3000") +conf, err := sdk.NewConfig("http://localhost:3000",sdk.Testnet) ``` Or using the *Mainnet* network ```go -conf, err := sdk.LoadMainnetConfig("http://localhost:3000") +conf, err := sdk.NewConfig("http://localhost:3000",sdk.Mainnet) ``` Construct a new Catapult client diff --git a/crypto/key_model.go b/crypto/key_model.go index ac89504..9bb07bc 100644 --- a/crypto/key_model.go +++ b/crypto/key_model.go @@ -32,6 +32,7 @@ type PrivateKey struct { Raw []byte } + // NewPrivateKey creates a new private key from []byte func NewPrivateKey(raw []byte) *PrivateKey { return &PrivateKey{(&big.Int{}).SetBytes(raw), raw} @@ -64,8 +65,7 @@ func NewPrivateKeyfromDecimalString(decimal string) (*PrivateKey, error) { } func (ref *PrivateKey) String() string { - - return string(ref.Raw) + return hex.EncodeToString(ref.Raw) } //PublicKey Represents a public key. diff --git a/examples/blockchain_api/main.go b/examples/blockchain_api/main.go index c1465c8..d5a70db 100644 --- a/examples/blockchain_api/main.go +++ b/examples/blockchain_api/main.go @@ -11,12 +11,15 @@ import ( "math/big" ) -const baseUrl = "http://localhost:3000" +const ( + baseUrl = "http://localhost:3000" + networkType = sdk.MijinTest +) // Simple Blockchain API request func main() { - conf, err := sdk.LoadTestnetConfig(baseUrl) + conf, err := sdk.NewConfig(baseUrl,networkType) if err != nil { panic(err) } diff --git a/examples/websocket/main.go b/examples/websocket/main.go index 58fd683..3787591 100644 --- a/examples/websocket/main.go +++ b/examples/websocket/main.go @@ -21,12 +21,12 @@ const ( // The notification is received in real time without having to poll the API waiting for a reply. func main() { - conf, err := sdk.LoadTestnetConfig(baseUrl) + conf, err := sdk.NewConfig(baseUrl,networkType) if err != nil { panic(err) } - acc, err := sdk.NewAccount(privateKey, networkType) + acc, err := sdk.NewAccountFromPrivateKey(privateKey, networkType) ws, err := sdk.NewConnectWs(baseUrl) if err != nil { diff --git a/sdk/account.go b/sdk/account.go index 639f6bf..1b05fdc 100644 --- a/sdk/account.go +++ b/sdk/account.go @@ -13,6 +13,8 @@ import ( type AccountService service + + func (a *AccountService) GetAccountInfo(ctx context.Context, address *Address) (*AccountInfo, *http.Response, error) { dto := &accountInfoDTO{} diff --git a/sdk/account_model.go b/sdk/account_model.go index 3cd84b4..c3acdc9 100644 --- a/sdk/account_model.go +++ b/sdk/account_model.go @@ -205,7 +205,7 @@ func (dto *multisigAccountInfoDTO) toStruct(networkType NetworkType) (*MultisigA cs := make([]*PublicAccount, len(dto.Multisig.Cosignatories)) ms := make([]*PublicAccount, len(dto.Multisig.MultisigAccounts)) - acc, err := NewPublicAccount(dto.Multisig.Account, networkType) + acc, err := NewAccountFromPublicKey(dto.Multisig.Account, networkType) if err != nil { return nil, err } @@ -214,14 +214,14 @@ func (dto *multisigAccountInfoDTO) toStruct(networkType NetworkType) (*MultisigA go func() { defer wg.Done() for i, c := range dto.Multisig.Cosignatories { - cs[i], err = NewPublicAccount(c, networkType) + cs[i], err = NewAccountFromPublicKey(c, networkType) } }() go func() { defer wg.Done() for i, m := range dto.Multisig.MultisigAccounts { - ms[i], err = NewPublicAccount(m, networkType) + ms[i], err = NewAccountFromPublicKey(m, networkType) } }() @@ -285,7 +285,20 @@ func (dto multisigAccountGraphInfoDTOS) toStruct(networkType NetworkType) (*Mult var addressError = errors.New("wrong address") -func NewAccount(pKey string, networkType NetworkType) (*Account, error) { +func NewAccount(networkType NetworkType) (*Account, error) { + kp, err := crypto.NewKeyPairByEngine(crypto.CryptoEngines.DefaultEngine) + if err != nil { + return nil, err + } + + pa, err := NewAccountFromPublicKey(kp.PublicKey.String(), networkType) + if err != nil { + return nil, err + } + + return &Account{pa, kp}, nil +} +func NewAccountFromPrivateKey(pKey string, networkType NetworkType) (*Account, error) { k, err := crypto.NewPrivateKeyfromHexString(pKey) if err != nil { return nil, err @@ -296,7 +309,7 @@ func NewAccount(pKey string, networkType NetworkType) (*Account, error) { return nil, err } - pa, err := NewPublicAccount(kp.PublicKey.String(), networkType) + pa, err := NewAccountFromPublicKey(kp.PublicKey.String(), networkType) if err != nil { return nil, err } @@ -304,7 +317,7 @@ func NewAccount(pKey string, networkType NetworkType) (*Account, error) { return &Account{pa, kp}, nil } -func NewPublicAccount(pKey string, networkType NetworkType) (*PublicAccount, error) { +func NewAccountFromPublicKey(pKey string, networkType NetworkType) (*PublicAccount, error) { ad, err := NewAddressFromPublicKey(pKey, networkType) if err != nil { return nil, err diff --git a/sdk/account_model_test.go b/sdk/account_model_test.go index 6c09661..bba6438 100644 --- a/sdk/account_model_test.go +++ b/sdk/account_model_test.go @@ -18,6 +18,18 @@ var testAddressesForEncoded = map[NetworkType]string{ MainNet: "NARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJFJKUV32", } +func TestGenerateNewAccount_NEM(t *testing.T) { + acc, err := NewAccount(MijinTest) + if err != nil { + t.Fatal("Error") + } + a := acc.KeyPair.PrivateKey.String() + t.Log("Private Key: " + a) + + assert.NotNil(t,acc.KeyPair.PrivateKey.String(),"Error generating new KeyPair") + + +} func TestGenerateEncodedAddress_NEM(t *testing.T) { for nType, testAddress := range testAddressesForEncoded { diff --git a/sdk/blockchain_model.go b/sdk/blockchain_model.go index d9b239e..2cdc1bd 100644 --- a/sdk/blockchain_model.go +++ b/sdk/blockchain_model.go @@ -87,7 +87,7 @@ type blockInfoDTO struct { func (dto *blockInfoDTO) toStruct() (*BlockInfo, error) { nt := ExtractNetworkType(dto.Block.Version) - pa, err := NewPublicAccount(dto.Block.Signer, nt) + pa, err := NewAccountFromPublicKey(dto.Block.Signer, nt) if err != nil { return nil, err } diff --git a/sdk/blockchain_test.go b/sdk/blockchain_test.go index 27e4170..6b38401 100644 --- a/sdk/blockchain_test.go +++ b/sdk/blockchain_test.go @@ -110,7 +110,7 @@ var wantBlockInfo *BlockInfo func init() { addRouters(bcRouters) - pubAcc, _ := NewPublicAccount("321DE652C4D3362FC2DDF7800F6582F4A10CFEA134B81F8AB6E4BE78BBA4D18E", MijinTest) + pubAcc, _ := NewAccountFromPublicKey("321DE652C4D3362FC2DDF7800F6582F4A10CFEA134B81F8AB6E4BE78BBA4D18E", MijinTest) wantBlockInfo = &BlockInfo{ NetworkType: MijinTest, diff --git a/sdk/mosaic.go b/sdk/mosaic.go index 3c40191..618edc8 100644 --- a/sdk/mosaic.go +++ b/sdk/mosaic.go @@ -154,7 +154,7 @@ func (dto mosaicPropertiesDTO) toStruct() *MosaicProperties { func (ref *mosaicInfoDTO) setMosaicInfo() (*MosaicInfo, error) { - publicAcc, err := NewPublicAccount(ref.Mosaic.Owner, NetworkType(1)) + publicAcc, err := NewAccountFromPublicKey(ref.Mosaic.Owner, NetworkType(1)) if err != nil { return nil, err } diff --git a/sdk/mosaic_test.go b/sdk/mosaic_test.go index 8442270..4f17dbb 100644 --- a/sdk/mosaic_test.go +++ b/sdk/mosaic_test.go @@ -93,7 +93,7 @@ var ( func TestMosaicService_GetMosaic(t *testing.T) { - mscInfo, resp, err := serv.Mosaic.GetMosaic(ctx, *testMosaicId) + mscInfo, resp, err := serv.Mosaic.GetMosaic(ctx, testMosaicId) if err != nil { t.Error(err) } else if validateResp(resp, t) && validateMosaicInfo(mscInfo, t) { @@ -137,7 +137,6 @@ func TestMosaicService_GetMosaicNames(t *testing.T) { } func TestMosaicService_GetMosaicsFromNamespace(t *testing.T) { - mscInfoArr, resp, err := serv.Mosaic.GetMosaicsFromNamespace(ctx, testNamespaceId, testMosaicId, pageSize) if err != nil { t.Error(err) @@ -150,6 +149,7 @@ func TestMosaicService_GetMosaicsFromNamespace(t *testing.T) { if err != nil { t.Error(err) } else if validateResp(resp, t) { + t.Log(t) t.Logf("%v", mscInfoArr) } @@ -159,11 +159,6 @@ func TestMosaicService_GetMosaicsFromNamespace(t *testing.T) { const iter = 1000 func TestMosaicService_GetMosaicsFromNamespasceExt(t *testing.T) { - - cfg, _ := LoadMainnetConfig("http://190.216.224.11:3000") - - serv := NewClient(nil, cfg) - h, _, err := serv.Blockchain.GetBlockchainHeight(ctx) if err != nil { t.Fatal(err) @@ -213,7 +208,7 @@ func TestMosaicService_GetMosaicsFromNamespasceExt(t *testing.T) { t.Log(tran) continue } - mscInfo, resp, err := serv.Mosaic.GetMosaic(ctx, *tran.MosaicId) + mscInfo, resp, err := serv.Mosaic.GetMosaic(ctx, tran.MosaicId) if err != nil { t.Error(err) } else if validateResp(resp, t) { diff --git a/sdk/namespace.go b/sdk/namespace.go index cc0e80c..e9c4740 100644 --- a/sdk/namespace.go +++ b/sdk/namespace.go @@ -171,7 +171,7 @@ type namespaceInfoDTO struct { //getNamespaceInfo create & return new NamespaceInfo from namespaceInfoDTO func (ref *namespaceInfoDTO) getNamespaceInfo() (*NamespaceInfo, error) { - pubAcc, err := NewPublicAccount(ref.Namespace.Owner, NetworkType(ref.Namespace.Type)) + pubAcc, err := NewAccountFromPublicKey(ref.Namespace.Owner, NetworkType(ref.Namespace.Type)) if err != nil { return nil, err } diff --git a/sdk/namespace_test.go b/sdk/namespace_test.go index 5cf2264..9cc753f 100644 --- a/sdk/namespace_test.go +++ b/sdk/namespace_test.go @@ -115,11 +115,11 @@ func TestNamespaceService_GetNamespacesFromAccount(t *testing.T) { if err != nil { t.Error(err) } else if validateResp(resp, t) { - if len(nsInfoArr.list) != 1 { + if len(nsInfoArr.List) != 1 { t.Error("return result must have length = 1") } else { isValid := true - for _, nsInfo := range nsInfoArr.list { + for _, nsInfo := range nsInfoArr.List { isValid = isValid && validateNamespaceInfo(nsInfo, t) } if isValid { @@ -137,11 +137,11 @@ func TestNamespaceService_GetNamespacesFromAccounts(t *testing.T) { if err != nil { t.Error(err) } else if validateResp(resp, t) { - if len(nsInfoArr.list) != 1 { + if len(nsInfoArr.List) != 1 { t.Error("return result must have length = 1") } else { isValid := true - for _, nsInfo := range nsInfoArr.list { + for _, nsInfo := range nsInfoArr.List { isValid = isValid && validateNamespaceInfo(nsInfo, t) } if isValid { diff --git a/sdk/sdk_model.go b/sdk/sdk_model.go index 30bb396..7642785 100644 --- a/sdk/sdk_model.go +++ b/sdk/sdk_model.go @@ -6,7 +6,7 @@ package sdk import ( "encoding/binary" - "github.com/Wondertan/nem2-sdk-go/utils" + "github.com/proximax-storage/nem2-sdk-go/utils" "math/big" "strconv" ) diff --git a/sdk/transaction_model.go b/sdk/transaction_model.go index 9f5d650..8ae425d 100644 --- a/sdk/transaction_model.go +++ b/sdk/transaction_model.go @@ -122,7 +122,7 @@ func (dto *abstractTransactionDTO) toStruct(tInfo *TransactionInfo) (*abstractTr return nil, err } - pa, err := NewPublicAccount(dto.Signer, nt) + pa, err := NewAccountFromPublicKey(dto.Signer, nt) if err != nil { return nil, err } @@ -1405,7 +1405,7 @@ type aggregateTransactionCosignatureDTO struct { } func (dto *aggregateTransactionCosignatureDTO) toStruct(networkType NetworkType) (*AggregateTransactionCosignature, error) { - acc, err := NewPublicAccount(dto.Signer, networkType) + acc, err := NewAccountFromPublicKey(dto.Signer, networkType) if err != nil { return nil, err } @@ -1449,7 +1449,7 @@ type multisigCosignatoryModificationDTO struct { } func (dto *multisigCosignatoryModificationDTO) toStruct(networkType NetworkType) (*MultisigCosignatoryModification, error) { - acc, err := NewPublicAccount(dto.PublicAccount, networkType) + acc, err := NewAccountFromPublicKey(dto.PublicAccount, networkType) if err != nil { return nil, err } diff --git a/sdk/transaction_test.go b/sdk/transaction_test.go index d653461..61463f3 100644 --- a/sdk/transaction_test.go +++ b/sdk/transaction_test.go @@ -203,7 +203,7 @@ func TestAggregateTransactionSerialization(t *testing.T) { 228, 129, 11, 242, 3, 144, 84, 65, 144, 80, 185, 131, 126, 250, 180, 187, 232, 164, 185, 187, 50, 216, 18, 249, 136, 92, 0, 216, 252, 22, 80, 225, 66, 1, 0, 1, 0, 41, 207, 95, 217, 65, 173, 37, 213, 128, 150, 152, 0, 0, 0, 0, 0} - p, err := NewPublicAccount("846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2", MijinTest) + p, err := NewAccountFromPublicKey("846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2", MijinTest) ttx, err := NewTransferTransaction( fakeDeadline, NewAddress("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", MijinTest), @@ -227,7 +227,7 @@ func TestAggregateTransactionSerialization(t *testing.T) { } func TestAggregateTransactionSigningWithMultipleCosignatures(t *testing.T) { - p, err := NewPublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", MijinTest) + p, err := NewAccountFromPublicKey("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", MijinTest) ttx, err := NewTransferTransaction( fakeDeadline, NewAddress("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", MijinTest), @@ -240,8 +240,8 @@ func TestAggregateTransactionSigningWithMultipleCosignatures(t *testing.T) { atx, err := NewCompleteAggregateTransaction(fakeDeadline, []Transaction{ttx}, MijinTest) - acc1, err := NewAccount("2a2b1f5d366a5dd5dc56c3c757cf4fe6c66e2787087692cf329d7a49a594658b", MijinTest) - acc2, err := NewAccount("b8afae6f4ad13a1b8aad047b488e0738a437c7389d4ff30c359ac068910c1d59", MijinTest) // TODO from original repo: "bug with private key" + acc1, err := NewAccountFromPrivateKey("2a2b1f5d366a5dd5dc56c3c757cf4fe6c66e2787087692cf329d7a49a594658b", MijinTest) + acc2, err := NewAccountFromPrivateKey("b8afae6f4ad13a1b8aad047b488e0738a437c7389d4ff30c359ac068910c1d59", MijinTest) // TODO from original repo: "bug with private key" stx, err := acc1.SignWithCosignatures(atx, []*Account{acc2}) @@ -267,7 +267,7 @@ func TestCosisignatureTransactionSigning(t *testing.T) { b := bytes.NewBufferString(rtx) tx, err := MapTransaction(b) atx := tx.(*AggregateTransaction) - acc, err := NewAccount("26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930", MijinTest) + acc, err := NewAccountFromPrivateKey("26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930", MijinTest) ctx, err := NewCosignatureTransaction(atx) cstx, err := acc.SignCosignatureTransaction(ctx) @@ -345,7 +345,7 @@ func TestTransferTransactionToAggregate(t *testing.T) { for i, w := range want1 { want[i] = byte(w) } - p, err := NewPublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) + p, err := NewAccountFromPublicKey("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) tx, err := NewTransferTransaction( fakeDeadline, NewAddress("SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM", MijinTest), @@ -370,7 +370,7 @@ func TestTransferTransactionSigning(t *testing.T) { "00000000000010000000000000090E8FEBD671DD41BEE94EC3BA5831CB608A312C2F203BA84AC01000100672B0000CE56000064000000" + "00000000" want1 := "350AE56BC97DB805E2098AB2C596FA4C6B37EF974BF24DFD61CD9F77C7687424" - a, err := NewAccount("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) + a, err := NewAccountFromPrivateKey("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) tx, err := NewTransferTransaction( fakeDeadline, @@ -398,8 +398,8 @@ func TestModifyMultisigAccountTransactionSerialization(t *testing.T) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 144, 85, 65, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 0, 104, 179, 251, 177, 135, 41, 193, 253, 226, 37, 197, 127, 140, 224, 128, 250, 130, 143, 0, 103, 228, 81, 163, 253, 129, 250, 98, 136, 66, 176, 183, 99, 0, 207, 137, 63, 252, 196, 124, 51, 231, 246, 138, 177, 219, 86, 54, 92, 21, 107, 7, 54, 130, 74, 12, 30, 39, 63, 158, 0, 184, 223, 143, 1, 235} - acc1, err := NewPublicAccount("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", MijinTest) - acc2, err := NewPublicAccount("cf893ffcc47c33e7f68ab1db56365c156b0736824a0c1e273f9e00b8df8f01eb", MijinTest) + acc1, err := NewAccountFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", MijinTest) + acc2, err := NewAccountFromPublicKey("cf893ffcc47c33e7f68ab1db56365c156b0736824a0c1e273f9e00b8df8f01eb", MijinTest) tx, err := NewModifyMultisigAccountTransaction( fakeDeadline, 2, @@ -499,7 +499,7 @@ func TestLockFundsTransactionToAggregate(t *testing.T) { for i, w := range want1 { want[i] = byte(w) } - p, err := NewPublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) + p, err := NewAccountFromPublicKey("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) stx := &SignedTransaction{AggregateBonded, "payload", "8498B38D89C1DC8A448EA5824938FF828926CD9F7747B1844B59B4B6807E878B"} tx, err := NewLockFundsTransaction(fakeDeadline, XemRelative(10), big.NewInt(100), stx, MijinTest) tx.Signer = p @@ -516,7 +516,7 @@ func TestLockFundsTransactionToAggregate(t *testing.T) { func TestLockFundsTransactionSigning(t *testing.T) { want := "B0000000D079047B87DCEDA0DE68558C1322A453D55D52BDA2778D66C5344BF79EE9E946C731F9ED565E5A854AFC0A1E1476B571940F920F33ADD9BAC245DB46A59794051026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF3775503904C410000000000000000010000000000000029CF5FD941AD25D5809698000000000064000000000000008498B38D89C1DC8A448EA5824938FF828926CD9F7747B1844B59B4B6807E878B" - acc, err := NewAccount("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) + acc, err := NewAccountFromPrivateKey("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) stx := &SignedTransaction{AggregateBonded, "payload", "8498B38D89C1DC8A448EA5824938FF828926CD9F7747B1844B59B4B6807E878B"} tx, err := NewLockFundsTransaction(fakeDeadline, XemRelative(10), big.NewInt(100), stx, MijinTest) @@ -568,7 +568,7 @@ func TestSecretLockTransactionToAggregate(t *testing.T) { for i, w := range want1 { want[i] = byte(w) } - p, err := NewPublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) + p, err := NewAccountFromPublicKey("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) ad, err := NewAddressFromRaw("SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM") s := "b778a39a3663719dfc5e48c9d78431b1e45c2af9df538782bf199c189dabeac7680ada57dcec8eee91c4e3bf3bfa9af6ffde90cd1d249d1c6121d7b759a001b1" tx, err := NewSecretLockTransaction(fakeDeadline, XemRelative(10), big.NewInt(100), SHA3_512, s, ad, MijinTest) @@ -586,7 +586,7 @@ func TestSecretLockTransactionToAggregate(t *testing.T) { func TestSecretLockTransactionSigning(t *testing.T) { want := "EA0000005A3B75AE172855381353250EA9A1DFEB86E9280C0006B8FD997C2FCECF211C9A260E76CB704A22EAD4648F18E6931381921A4EDC7D309C32275D0147E9BAD3051026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF3775503904C420000000000000000010000000000000029CF5FD941AD25D58096980000000000640000000000000000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7680ADA57DCEC8EEE91C4E3BF3BFA9AF6FFDE90CD1D249D1C6121D7B759A001B190E8FEBD671DD41BEE94EC3BA5831CB608A312C2F203BA84AC" s := "b778a39a3663719dfc5e48c9d78431b1e45c2af9df538782bf199c189dabeac7680ada57dcec8eee91c4e3bf3bfa9af6ffde90cd1d249d1c6121d7b759a001b1" - acc, err := NewAccount("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) + acc, err := NewAccountFromPrivateKey("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) ad, err := NewAddressFromRaw("SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM") tx, err := NewSecretLockTransaction(fakeDeadline, XemRelative(10), big.NewInt(100), SHA3_512, s, ad, MijinTest) b, err := acc.Sign(tx) @@ -639,7 +639,7 @@ func TestSecretProofTransactionToAggregate(t *testing.T) { for i, w := range want1 { want[i] = byte(w) } - p, err := NewPublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) + p, err := NewAccountFromPublicKey("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", MijinTest) s := "b778a39a3663719dfc5e48c9d78431b1e45c2af9df538782bf199c189dabeac7680ada57dcec8eee91c4e3bf3bfa9af6ffde90cd1d249d1c6121d7b759a001b1" ss := "9a493664" tx, err := NewSecretProofTransaction(fakeDeadline, SHA3_512, s, ss, MijinTest) @@ -656,7 +656,7 @@ func TestSecretProofTransactionToAggregate(t *testing.T) { func TestSecretProofTransactionSigning(t *testing.T) { want := "BF000000147827E5FDAB2201ABD3663964B0493166DA7DD18497718F53DF09AAFC55271B57A9E81B4E2F627FD19E9E9B77283D1620FB8E9E32BAC5AC265EB0B43C75B4071026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF3775503904C430000000000000000010000000000000000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7680ADA57DCEC8EEE91C4E3BF3BFA9AF6FFDE90CD1D249D1C6121D7B759A001B104009A493664" - acc, err := NewAccount("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) + acc, err := NewAccountFromPrivateKey("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", MijinTest) s := "b778a39a3663719dfc5e48c9d78431b1e45c2af9df538782bf199c189dabeac7680ada57dcec8eee91c4e3bf3bfa9af6ffde90cd1d249d1c6121d7b759a001b1" ss := "9a493664"