-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
liquid: drop the flat fee for mempool policy patch
elements releases have the mempool policy patch. To apply ct discount on peerswap, we uses An "Ask forgiveness not permission" approach, where we attempt to broadcast with the discounted fee, and if that fails, we retry with the non-discounted fee. The discount is achieved by calculating the fee based on a discounted vsize (equivalent to 1/4 of the original tx size).
- Loading branch information
1 parent
5935fb4
commit 6ff417c
Showing
9 changed files
with
252 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package lwk | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
// electrumRPCError represents the structure of an RPC error response | ||
type electrumRPCError struct { | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// Regular expression to match RPC error messages with any prefix | ||
var re = regexp.MustCompile(`^(.*) RPC error: (.*)$`) | ||
|
||
// parseRPCError parses an error and extracts the RPC error code and message if present | ||
func parseRPCError(err error) (*electrumRPCError, error) { | ||
var rpcErr electrumRPCError | ||
errStr := err.Error() | ||
|
||
matches := re.FindStringSubmatch(errStr) | ||
|
||
if len(matches) == 3 { // Prefix and JSON payload extracted successfully | ||
errJSON := matches[2] | ||
if jerr := json.Unmarshal([]byte(errJSON), &rpcErr); jerr != nil { | ||
return nil, fmt.Errorf("error parsing rpc error: %v", jerr) | ||
} | ||
} else { | ||
// If no RPC error pattern is found, return the original error | ||
return nil, errors.New(errStr) | ||
} | ||
|
||
return &rpcErr, nil | ||
} |
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 lwk | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestParseRPCError(t *testing.T) { | ||
t.Parallel() | ||
testCases := map[string]struct { | ||
err error | ||
expectedCode int | ||
expectedMsg string | ||
wantErr bool | ||
}{ | ||
"Valid RPC error": { | ||
err: errors.New("sendrawtransaction RPC error: {\"code\":-26,\"message\":\"min relay fee not met\"}"), | ||
expectedCode: -26, | ||
expectedMsg: "min relay fee not met", | ||
wantErr: false, | ||
}, | ||
"Invalid JSON payload": { | ||
|
||
err: errors.New("RPC error: {invalid json}"), | ||
expectedCode: 0, | ||
expectedMsg: "", | ||
wantErr: true, | ||
}, | ||
"No RPC error pattern": { | ||
err: errors.New("Some other error"), | ||
expectedCode: 0, | ||
expectedMsg: "", | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
rpcErr, err := parseRPCError(tc.err) | ||
if (err != nil) != tc.wantErr { | ||
t.Errorf("wantErr: %v, got error: %v", tc.wantErr, err) | ||
} | ||
if err == nil { | ||
if rpcErr.Code != tc.expectedCode { | ||
t.Errorf("expected code: %d, got: %d", tc.expectedCode, rpcErr.Code) | ||
} | ||
if rpcErr.Message != tc.expectedMsg { | ||
t.Errorf("expected message: %s, got: %s", tc.expectedMsg, rpcErr.Message) | ||
} | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.