-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.swift
78 lines (73 loc) · 2.67 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import DiemTypes
func demo_peer_to_peer_script() throws {
let address = DiemTypes.AccountAddress(value: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
let module = DiemTypes.Identifier(value: "XDX")
let name = DiemTypes.Identifier(value: "XDX")
let type_params: [DiemTypes.TypeTag] = []
let struct_tag = DiemTypes.StructTag(
address: address,
module: module,
name: name,
type_params: type_params
)
let token = DiemTypes.TypeTag.Struct(struct_tag)
let payee = DiemTypes.AccountAddress(value: [
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22,
])
let amount: UInt64 = 1234567
let script = encode_peer_to_peer_with_metadata_script(
currency: token,
payee: payee,
amount: amount,
metadata: [],
metadata_signature: []
)
switch try decode_peer_to_peer_with_metadata_script(script: script) {
case .PeerToPeerWithMetadata(_, let p, let a, _, _):
assert(p == payee, "Payee doesn't match")
assert(a == amount, "Amount doesn't match")
default: assertionFailure("Invalid scriptcall")
}
for o in try script.bcsSerialize() {
print(o, terminator: " ")
}
print()
}
func demo_peer_to_peer_script_function() throws {
let address = DiemTypes.AccountAddress(value: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
let module = DiemTypes.Identifier(value: "XDX")
let name = DiemTypes.Identifier(value: "XDX")
let type_params: [DiemTypes.TypeTag] = []
let struct_tag = DiemTypes.StructTag(
address: address,
module: module,
name: name,
type_params: type_params
)
let token = DiemTypes.TypeTag.Struct(struct_tag)
let payee = DiemTypes.AccountAddress(value: [
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22,
])
let amount: UInt64 = 1234567
let script = try PaymentScripts.encode_peer_to_peer_with_metadata_script_function(
currency: token,
payee: payee,
amount: amount,
metadata: [],
metadata_signature: []
)
switch try PaymentScripts.decode_peer_to_peer_with_metadata_script_function(payload: script) {
case .PeerToPeerWithMetadata(_, let p, let a, _, _):
assert(p == payee, "Payee doesn't match")
assert(a == amount, "Amount doesn't match")
default: assertionFailure("Invalid script function call")
}
for o in try script.bcsSerialize() {
print(o, terminator: " ")
}
print()
}
try demo_peer_to_peer_script()
try demo_peer_to_peer_script_function()