This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
220 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CancelSchema { | ||
static const String json = r''' | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://tbdex.dev/cancel.schema.json", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"reason": { | ||
"type": "string" | ||
} | ||
} | ||
}'''; | ||
} |
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
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,69 @@ | ||
import 'package:tbdex/src/protocol/models/message.dart'; | ||
import 'package:tbdex/src/protocol/models/message_data.dart'; | ||
import 'package:tbdex/src/protocol/parser.dart'; | ||
|
||
class Cancel extends Message { | ||
@override | ||
final MessageMetadata metadata; | ||
@override | ||
final CancelData data; | ||
|
||
@override | ||
Set<MessageKind> get validNext => {}; | ||
|
||
Cancel._({ | ||
required this.metadata, | ||
required this.data, | ||
String? signature, | ||
}) : super() { | ||
this.signature = signature; | ||
} | ||
|
||
static Cancel create( | ||
String to, | ||
String from, | ||
String exchangeId, | ||
CancelData data, { | ||
String? externalId, | ||
String protocol = '1.0', | ||
}) { | ||
final now = DateTime.now().toUtc().toIso8601String(); | ||
final metadata = MessageMetadata( | ||
kind: MessageKind.cancel, | ||
to: to, | ||
from: from, | ||
id: Message.generateId(MessageKind.cancel), | ||
exchangeId: exchangeId, | ||
createdAt: now, | ||
protocol: protocol, | ||
externalId: externalId, | ||
); | ||
|
||
return Cancel._( | ||
metadata: metadata, | ||
data: data, | ||
); | ||
} | ||
|
||
static Future<Cancel> parse(String rawMessage) async { | ||
final cancel = Parser.parseMessage(rawMessage) as Cancel; | ||
await cancel.verify(); | ||
return cancel; | ||
} | ||
|
||
factory Cancel.fromJson(Map<String, dynamic> json) { | ||
return Cancel._( | ||
metadata: MessageMetadata.fromJson(json['metadata']), | ||
data: CancelData.fromJson(json['data']), | ||
signature: json['signature'], | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'metadata': metadata.toJson(), | ||
'data': data.toJson(), | ||
'signature': signature, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ enum MessageKind { | |
rfq, | ||
quote, | ||
close, | ||
cancel, | ||
order, | ||
orderstatus, | ||
} | ||
|
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
Submodule tbdex
updated
15 files
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,40 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:tbdex/src/protocol/models/cancel.dart'; | ||
import 'package:tbdex/src/protocol/models/message.dart'; | ||
import 'package:tbdex/src/protocol/models/message_data.dart'; | ||
import 'package:tbdex/tbdex.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:typeid/typeid.dart'; | ||
|
||
import '../../helpers/test_data.dart'; | ||
|
||
void main() async { | ||
await TestData.initializeDids(); | ||
|
||
group('Cancel', () { | ||
test('can create a new cancel', () { | ||
final cancel = Cancel.create( | ||
TestData.pfi, | ||
TestData.alice, | ||
TypeId.generate(MessageKind.cancel.name), | ||
CancelData(reason: 'my reason'), | ||
); | ||
|
||
expect(cancel.metadata.id, startsWith(MessageKind.cancel.name)); | ||
expect(cancel.metadata.kind, equals(MessageKind.cancel)); | ||
expect(cancel.metadata.protocol, equals('1.0')); | ||
expect(cancel.data.reason, equals('my reason')); | ||
}); | ||
|
||
test('can parse and verify cancel from a json string', () async { | ||
final cancel = TestData.getCancel(); | ||
await cancel.sign(TestData.aliceDid); | ||
final json = jsonEncode(cancel.toJson()); | ||
final parsed = await Cancel.parse(json); | ||
|
||
expect(parsed, isA<Cancel>()); | ||
expect(parsed.toString(), equals(json)); | ||
}); | ||
}); | ||
} |