Skip to content

Commit 4cf58a1

Browse files
committed
chore: update cw_mweb dependencies
chore: remove cw_core as dependency from cw_mweb
1 parent 8ec782c commit 4cf58a1

File tree

7 files changed

+124
-6
lines changed

7 files changed

+124
-6
lines changed

cw_mweb/go/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ go 1.24.1
44

55
require github.com/ltcmweb/mwebd v0.1.16
66

7+
require github.com/ltcmweb/mwebd v0.1.16
8+
79
require (
810
github.com/Microsoft/go-winio v0.6.2 // indirect
911
github.com/StackExchange/wmi v1.2.1 // indirect

cw_mweb/lib/cw_mweb.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'dart:developer';
44
import 'dart:io';
55
import 'dart:typed_data';
66

7-
import 'package:cw_core/utils/print_verbose.dart';
87
import 'package:cw_mweb/mweb_ffi.dart';
8+
import 'package:cw_mweb/print_verbose.dart';
99
import 'package:grpc/grpc.dart';
1010
import 'package:path_provider/path_provider.dart';
1111
import 'mwebd.pbgrpc.dart';
@@ -247,4 +247,15 @@ class CwMweb {
247247
_rpcClient = await stub();
248248
return await _rpcClient!.psbtExtract(request, options: CallOptions(timeout: TIMEOUT_DURATION));
249249
}
250+
static Future<PsbtResponse> psbtSign(PsbtSignRequest request) async {
251+
printV("mweb.psbtSign() called");
252+
_rpcClient = await stub();
253+
return await _rpcClient!.psbtSign(request, options: CallOptions(timeout: TIMEOUT_DURATION));
254+
}
255+
256+
static Future<PsbtResponse> psbtSignNonMweb(PsbtSignNonMwebRequest request) async {
257+
printV("mweb.psbtSignNonMweb() called");
258+
_rpcClient = await stub();
259+
return await _rpcClient!.psbtSignNonMweb(request, options: CallOptions(timeout: TIMEOUT_DURATION));
260+
}
250261
}

cw_mweb/lib/mweb_ffi.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'dart:ffi';
22
import 'dart:io';
33
import 'dart:typed_data';
44

5-
import 'package:cw_core/utils/print_verbose.dart';
65
import 'package:cw_mweb/generated_bindings.g.dart';
6+
import 'package:cw_mweb/print_verbose.dart';
77
import 'package:ffi/ffi.dart';
88

99
String libPath = (() {

cw_mweb/lib/mwebd.pb.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cw_mweb/lib/mwebd.pbgrpc.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cw_mweb/lib/print_verbose.dart

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import 'dart:io';
2+
import 'dart:math';
3+
import 'package:flutter/foundation.dart';
4+
5+
enum LogLevel { info, debug, warn, error }
6+
7+
/// Pass an optional [file] to also write the log to a file.
8+
void printV(
9+
dynamic content, {
10+
String? file,
11+
LogLevel level = LogLevel.info,
12+
}) {
13+
final programInfo = CustomTrace(StackTrace.current);
14+
final logLine =
15+
"[${level.name.toUpperCase()}] ${programInfo.fileName}#${programInfo.lineNumber}:${programInfo.columnNumber} ${programInfo.callerFunctionName}: $content";
16+
17+
print(logLine);
18+
19+
if (file != null) {
20+
final logFile = File(file);
21+
if (!logFile.existsSync()) {
22+
logFile.createSync(recursive: true);
23+
}
24+
logFile.writeAsStringSync("$logLine\n", mode: FileMode.append, flush: true);
25+
}
26+
}
27+
28+
// https://stackoverflow.com/a/59386101
29+
30+
class CustomTrace {
31+
final StackTrace _trace;
32+
33+
String? fileName;
34+
String? functionName;
35+
String? callerFunctionName;
36+
int? lineNumber;
37+
int? columnNumber;
38+
39+
CustomTrace(this._trace) {
40+
try {
41+
_parseTrace();
42+
} catch (e) {
43+
if (kDebugMode) print("Unable to parse trace (printV): $e");
44+
}
45+
}
46+
47+
String _getFunctionNameFromFrame(String frame) {
48+
/* Just giving another nickname to the frame */
49+
var currentTrace = frame;
50+
/* To get rid off the #number thing, get the index of the first whitespace */
51+
var indexOfWhiteSpace = currentTrace.indexOf(' ');
52+
53+
/* Create a substring from the first whitespace index till the end of the string */
54+
var subStr = currentTrace.substring(max(0, indexOfWhiteSpace));
55+
56+
/* Grab the function name using reg expr */
57+
var indexOfFunction = subStr.indexOf(RegExp(r'[A-Za-z0-9_]'));
58+
59+
/* Create a new substring from the function name index till the end of string */
60+
subStr = subStr.substring(indexOfFunction);
61+
62+
indexOfWhiteSpace = subStr.indexOf(RegExp(r'[ .]'));
63+
64+
/* Create a new substring from start to the first index of a whitespace. This substring gives us the function name */
65+
subStr = subStr.substring(0, max(0, indexOfWhiteSpace));
66+
67+
return subStr;
68+
}
69+
70+
void _parseTrace() {
71+
/* The trace comes with multiple lines of strings, (each line is also known as a frame), so split the trace's string by lines to get all the frames */
72+
var frames = this._trace.toString().split("\n");
73+
74+
/* The first frame is the current function */
75+
this.functionName = _getFunctionNameFromFrame(frames[0]);
76+
77+
/* The second frame is the caller function */
78+
this.callerFunctionName = _getFunctionNameFromFrame(frames[1]);
79+
80+
/* The first frame has all the information we need */
81+
var traceString = frames[1];
82+
83+
/* Search through the string and find the index of the file name by looking for the '.dart' regex */
84+
var indexOfFileName = traceString.indexOf(
85+
RegExp(r'[/A-Za-z_]+.dart'), 1); // 1 to offest and not print the printV function name
86+
87+
var fileInfo = traceString.substring(max(0, indexOfFileName));
88+
89+
var listOfInfos = fileInfo.split(":");
90+
91+
/* Splitting fileInfo by the character ":" separates the file name, the line number and the column counter nicely.
92+
Example: main.dart:5:12
93+
To get the file name, we split with ":" and get the first index
94+
To get the line number, we would have to get the second index
95+
To get the column number, we would have to get the third index
96+
*/
97+
try {
98+
this.fileName = listOfInfos[0];
99+
this.lineNumber = int.tryParse(listOfInfos[1]);
100+
var columnStr = listOfInfos[2];
101+
columnStr = columnStr.replaceFirst(")", "");
102+
this.columnNumber = int.tryParse(columnStr);
103+
} catch (e) {
104+
if (kDebugMode) print("Unable to parse trace (printV): $e");
105+
}
106+
}
107+
}

cw_mweb/pubspec.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ dependencies:
1313
grpc: ^4.0.1
1414
path_provider: ^2.1.2
1515
plugin_platform_interface: ^2.0.2
16-
cw_core:
17-
path: ../cw_core
1816
ffi: ^2.1.0
1917

2018
dev_dependencies:

0 commit comments

Comments
 (0)