-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ws transactions monitoring
- Loading branch information
Showing
8 changed files
with
306 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package solana | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/gagliardetto/solana-go/rpc" | ||
) | ||
|
||
type CommitmentStatus struct { | ||
s string | ||
} | ||
|
||
func (cs CommitmentStatus) String() string { | ||
return cs.s | ||
} | ||
|
||
// For more information, see https://docs.solanalabs.com/consensus/commitments | ||
var ( | ||
CommitmentFinalized = CommitmentStatus{"finalized"} | ||
CommitmentConfirmed = CommitmentStatus{"confirmed"} | ||
CommitmentProcessed = CommitmentStatus{"processed"} | ||
) | ||
|
||
func mapToCommitmentType(cs CommitmentStatus) (rpc.CommitmentType, error) { | ||
switch cs { | ||
case CommitmentFinalized: | ||
return rpc.CommitmentFinalized, nil | ||
case CommitmentConfirmed: | ||
return rpc.CommitmentConfirmed, nil | ||
case CommitmentProcessed: | ||
return rpc.CommitmentProcessed, nil | ||
} | ||
|
||
return "", errors.New("invalid CommitmentStatus") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package solana | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gagliardetto/solana-go/rpc" | ||
"github.com/test-go/testify/require" | ||
) | ||
|
||
func Test_mapToCommitmentType(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
cs CommitmentStatus | ||
want rpc.CommitmentType | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "processed", | ||
cs: CommitmentProcessed, | ||
want: rpc.CommitmentProcessed, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "confirmed", | ||
cs: CommitmentConfirmed, | ||
want: rpc.CommitmentConfirmed, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "finalized", | ||
cs: CommitmentFinalized, | ||
want: rpc.CommitmentFinalized, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid", | ||
cs: CommitmentStatus{}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got, err := mapToCommitmentType(tc.cs) | ||
if tc.wantErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.want, got) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.