forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[transaction-builder-generator] Add Swift support
Closes: aptos-labs#9632
- Loading branch information
1 parent
b887290
commit dbbc96c
Showing
15 changed files
with
797 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
78 changes: 78 additions & 0 deletions
78
diem-move/transaction-builder-generator/examples/swift/main.swift
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,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() |
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.