blockchain.transaction.broadcast implementation #80

Merged
moodyjon merged 9 commits from blockchain_tx_rpc2 into master 2022-12-16 20:54:20 +01:00
2 changed files with 1 additions and 35 deletions
Showing only changes of commit 5e977e59a2 - Show all commits

View file

@ -705,7 +705,7 @@ func (s *BlockchainScripthashService) Unsubscribe(req *ScripthashSubscribeReq, r
return nil
}
type TransactionBroadcastReq []string
type TransactionBroadcastReq [1]string
type TransactionBroadcastResp string
// 'blockchain.transaction.broadcast'

View file

@ -1,14 +1,12 @@
package server
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"hash"
"io"
"io/ioutil"
golog "log"
"net"
@ -242,38 +240,6 @@ func LoadDatabase(args *Args, grp *stop.Group) (*db.ReadOnlyDBColumnFamily, erro
return myDB, nil
}
type BasicAuthClientCodec struct {
client http.Client
url string
user string
password string
buff *bytes.Buffer
}
func (c BasicAuthClientCodec) Read(p []byte) (n int, err error) {
return c.buff.Read(p)
}
func (c BasicAuthClientCodec) Write(p []byte) (n int, err error) {
req, err := http.NewRequest("POST", c.url, bytes.NewReader(p))
if err != nil {
return 0, err
}
req.SetBasicAuth(c.user, c.password)
req.Header.Add("Content-Type", "application/json")
resp, err := c.client.Do(req)
if err != nil {
return len(p), err
}
io.Copy(c.buff, resp.Body)
return len(p), err
}
func (c BasicAuthClientCodec) Close() error {
c.client.CloseIdleConnections()
return nil
}
// MakeHubServer takes the arguments given to a hub when it's started and
// initializes everything. It loads information about previously known peers,
// creates needed internal data structures, and initializes goroutines.