1+ // Package localtxsubmission implements the Ouroboros local-tx-submission protocol
12package localtxsubmission
23
34import (
@@ -6,50 +7,54 @@ import (
67 "github.com/cloudstruct/go-ouroboros-network/protocol"
78)
89
10+ // Protocol identifiers
911const (
10- PROTOCOL_NAME = "local-tx-submission"
11- PROTOCOL_ID uint16 = 6
12+ protocolName = "local-tx-submission"
13+ protocolId uint16 = 6
1214)
1315
1416var (
15- STATE_IDLE = protocol .NewState (1 , "Idle" )
16- STATE_BUSY = protocol .NewState (2 , "Busy" )
17- STATE_DONE = protocol .NewState (3 , "Done" )
17+ stateIdle = protocol .NewState (1 , "Idle" )
18+ stateBusy = protocol .NewState (2 , "Busy" )
19+ stateDone = protocol .NewState (3 , "Done" )
1820)
1921
22+ // LocalTxSubmission protocol state machine
2023var StateMap = protocol.StateMap {
21- STATE_IDLE : protocol.StateMapEntry {
24+ stateIdle : protocol.StateMapEntry {
2225 Agency : protocol .AgencyClient ,
2326 Transitions : []protocol.StateTransition {
2427 {
25- MsgType : MESSAGE_TYPE_SUBMIT_TX ,
26- NewState : STATE_BUSY ,
28+ MsgType : MessageTypeSubmitTx ,
29+ NewState : stateBusy ,
2730 },
2831 },
2932 },
30- STATE_BUSY : protocol.StateMapEntry {
33+ stateBusy : protocol.StateMapEntry {
3134 Agency : protocol .AgencyServer ,
3235 Transitions : []protocol.StateTransition {
3336 {
34- MsgType : MESSAGE_TYPE_ACCEPT_TX ,
35- NewState : STATE_IDLE ,
37+ MsgType : MessageTypeAcceptTx ,
38+ NewState : stateIdle ,
3639 },
3740 {
38- MsgType : MESSAGE_TYPE_REJECT_TX ,
39- NewState : STATE_IDLE ,
41+ MsgType : MessageTypeRejectTx ,
42+ NewState : stateIdle ,
4043 },
4144 },
4245 },
43- STATE_DONE : protocol.StateMapEntry {
46+ stateDone : protocol.StateMapEntry {
4447 Agency : protocol .AgencyNone ,
4548 },
4649}
4750
51+ // LocalTxSubmission is a wrapper object that holds the client and server instances
4852type LocalTxSubmission struct {
4953 Client * Client
5054 Server * Server
5155}
5256
57+ // Config is used to configure the LocalTxSubmission protocol instance
5358type Config struct {
5459 SubmitTxFunc SubmitTxFunc
5560 Timeout time.Duration
@@ -58,6 +63,7 @@ type Config struct {
5863// Callback function types
5964type SubmitTxFunc func (interface {}) error
6065
66+ // New returns a new LocalTxSubmission object
6167func New (protoOptions protocol.ProtocolOptions , cfg * Config ) * LocalTxSubmission {
6268 l := & LocalTxSubmission {
6369 Client : NewClient (protoOptions , cfg ),
@@ -66,8 +72,10 @@ func New(protoOptions protocol.ProtocolOptions, cfg *Config) *LocalTxSubmission
6672 return l
6773}
6874
75+ // LocalTxSubmissionOptionFunc represents a function used to modify the LocalTxSubmission protocol config
6976type LocalTxSubmissionOptionFunc func (* Config )
7077
78+ // NewConfig returns a new LocalTxSubmission config object with the provided options
7179func NewConfig (options ... LocalTxSubmissionOptionFunc ) Config {
7280 c := Config {
7381 Timeout : 30 * time .Second ,
@@ -79,12 +87,14 @@ func NewConfig(options ...LocalTxSubmissionOptionFunc) Config {
7987 return c
8088}
8189
90+ // WithSubmitTxFunc specifies the callback function when a TX is submitted when acting as a server
8291func WithSubmitTxFunc (submitTxFunc SubmitTxFunc ) LocalTxSubmissionOptionFunc {
8392 return func (c * Config ) {
8493 c .SubmitTxFunc = submitTxFunc
8594 }
8695}
8796
97+ // WithTimeout specifies the timeout for a TX submit operation when acting as a client
8898func WithTimeout (timeout time.Duration ) LocalTxSubmissionOptionFunc {
8999 return func (c * Config ) {
90100 c .Timeout = timeout
0 commit comments