Skip to content

Commit

Permalink
[rename] update transaction-builder-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
davidiw authored and aptos-bot committed Mar 12, 2022
1 parent ce395c1 commit 8ed58a3
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 268 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

#include "diem_framework.hpp"
#include "aptos_framework.hpp"
#include "aptos_types.hpp"
#include <memory>

using namespace diem_framework;
using namespace aptos_framework;
using namespace aptos_types;

void demo_p2p_script() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Diem.Stdlib;
using Diem.Types;
using Aptos.Stdlib;
using Aptos.Types;
using Serde;
using System.Diagnostics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ package main

import (
"fmt"
stdlib "testing/diemstdlib"
diem "testing/diemtypes"
stdlib "testing/aptosstdlib"
aptos "testing/aptostypes"
)

func demo_p2p_script() {
token := &diem.TypeTag__Struct{
Value: diem.StructTag{
Address: diem.AccountAddress(
token := &aptos.TypeTag__Struct{
Value: aptos.StructTag{
Address: aptos.AccountAddress(
[16]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
),
Module: diem.Identifier("XDX"),
Name: diem.Identifier("XDX"),
TypeParams: []diem.TypeTag{},
Module: aptos.Identifier("XDX"),
Name: aptos.Identifier("XDX"),
TypeParams: []aptos.TypeTag{},
},
}
payee := diem.AccountAddress(
payee := aptos.AccountAddress(
[16]uint8{0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22},
)
amount := uint64(1_234_567)
Expand All @@ -46,17 +46,17 @@ func demo_p2p_script() {
}

func demo_p2p_script_function() {
token := &diem.TypeTag__Struct{
Value: diem.StructTag{
Address: diem.AccountAddress(
token := &aptos.TypeTag__Struct{
Value: aptos.StructTag{
Address: aptos.AccountAddress(
[16]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
),
Module: diem.Identifier("XDX"),
Name: diem.Identifier("XDX"),
TypeParams: []diem.TypeTag{},
Module: aptos.Identifier("XDX"),
Name: aptos.Identifier("XDX"),
TypeParams: []aptos.TypeTag{},
},
}
payee := diem.AccountAddress(
payee := aptos.AccountAddress(
[16]uint8{0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22},
)
amount := uint64(1_234_567)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

import com.novi.serde.Bytes;
import com.novi.serde.Unsigned; // used as documentation.
import com.diem.stdlib.Helpers;
import com.diem.stdlib.ScriptCall;;
import com.diem.stdlib.ScriptFunctionCall;;
import com.diem.types.AccountAddress;
import com.diem.types.Identifier;
import com.diem.types.Script;
import com.diem.types.StructTag;
import com.diem.types.TypeTag;
import com.diem.types.TransactionPayload;
import com.aptos.stdlib.Helpers;
import com.aptos.stdlib.ScriptCall;;
import com.aptos.stdlib.ScriptFunctionCall;;
import com.aptos.types.AccountAddress;
import com.aptos.types.Identifier;
import com.aptos.types.Script;
import com.aptos.types.StructTag;
import com.aptos.types.TypeTag;
import com.aptos.types.TransactionPayload;

public class StdlibDemo {
private static void demo_p2p_script() throws Exception {
StructTag.Builder builder = new StructTag.Builder();
builder.address = AccountAddress.valueOf(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1});
builder.module = new Identifier("XDX");
builder.name = new Identifier("XDX");
builder.type_params = new ArrayList<com.diem.types.TypeTag>();
builder.type_params = new ArrayList<com.aptos.types.TypeTag>();
StructTag tag = builder.build();

TypeTag token = new TypeTag.Struct(tag);
Expand Down Expand Up @@ -50,7 +50,7 @@ private static void demo_p2p_script_function() throws Exception {
builder.address = AccountAddress.valueOf(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1});
builder.module = new Identifier("XDX");
builder.name = new Identifier("XDX");
builder.type_params = new ArrayList<com.diem.types.TypeTag>();
builder.type_params = new ArrayList<com.aptos.types.TypeTag>();
StructTag tag = builder.build();

TypeTag token = new TypeTag.Struct(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

# pyre-strict

import aptos_types as diem
import aptos_types as aptos
import serde_types as st
import diem_framework as stdlib
import aptos_framework as stdlib


def demo_p2p_script() -> None:
token = diem.TypeTag__Struct(
value=diem.StructTag(
address=diem.AccountAddress.from_bytes(b"\x00" * 15 + b"\x01"),
module=diem.Identifier("XDX"),
name=diem.Identifier("XDX"),
token = aptos.TypeTag__Struct(
value=aptos.StructTag(
address=aptos.AccountAddress.from_bytes(b"\x00" * 15 + b"\x01"),
module=aptos.Identifier("XDX"),
name=aptos.Identifier("XDX"),
type_params=[],
)
)
payee = diem.AccountAddress.from_bytes(b"\x22" * 16)
payee = aptos.AccountAddress.from_bytes(b"\x22" * 16)
amount = st.uint64(1_234_567)
script = stdlib.encode_peer_to_peer_with_metadata_script(token, payee, amount, b"", b"")

Expand All @@ -31,15 +31,15 @@ def demo_p2p_script() -> None:
print()

def demo_p2p_script_function() -> None:
token = diem.TypeTag__Struct(
value=diem.StructTag(
address=diem.AccountAddress.from_bytes(b"\x00" * 15 + b"\x01"),
module=diem.Identifier("XDX"),
name=diem.Identifier("XDX"),
token = aptos.TypeTag__Struct(
value=aptos.StructTag(
address=aptos.AccountAddress.from_bytes(b"\x00" * 15 + b"\x01"),
module=aptos.Identifier("XDX"),
name=aptos.Identifier("XDX"),
type_params=[],
)
)
payee = diem.AccountAddress.from_bytes(b"\x22" * 16)
payee = aptos.AccountAddress.from_bytes(b"\x22" * 16)
amount = st.uint64(1_234_567)
payload = stdlib.encode_peer_to_peer_with_metadata_script_function(token, payee, amount, b"", b"")

Expand Down
30 changes: 15 additions & 15 deletions aptos-move/transaction-builder-generator/examples/swift/main.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import DiemTypes
import AptosTypes

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(
let address = AptosTypes.AccountAddress(value: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
let module = AptosTypes.Identifier(value: "XDX")
let name = AptosTypes.Identifier(value: "XDX")
let type_params: [AptosTypes.TypeTag] = []
let struct_tag = AptosTypes.StructTag(
address: address,
module: module,
name: name,
type_params: type_params
)
let token = DiemTypes.TypeTag.Struct(struct_tag)
let payee = DiemTypes.AccountAddress(value: [
let token = AptosTypes.TypeTag.Struct(struct_tag)
let payee = AptosTypes.AccountAddress(value: [
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22,
])
Expand All @@ -38,18 +38,18 @@ func demo_peer_to_peer_script() throws {
}

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(
let address = AptosTypes.AccountAddress(value: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
let module = AptosTypes.Identifier(value: "XDX")
let name = AptosTypes.Identifier(value: "XDX")
let type_params: [AptosTypes.TypeTag] = []
let struct_tag = AptosTypes.StructTag(
address: address,
module: module,
name: name,
type_params: type_params
)
let token = DiemTypes.TypeTag.Struct(struct_tag)
let payee = DiemTypes.AccountAddress(value: [
let token = AptosTypes.TypeTag.Struct(struct_tag)
let payee = AptosTypes.AccountAddress(value: [
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22,
])
Expand Down
32 changes: 16 additions & 16 deletions aptos-move/transaction-builder-generator/examples/typescript/mod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

import * as DiemStdlib from "./diemStdlib/mod.ts";
import * as DiemTypes from "./diemTypes/mod.ts";
import * as AptosStdlib from "./aptosStdlib/mod.ts";
import * as AptosTypes from "./aptosTypes/mod.ts";
import { BcsSerializer } from "./bcs/mod.ts";
import { ListTuple } from "./serde/mod.ts";
import { equal } from "https://deno.land/x/equal/mod.ts";
Expand All @@ -12,26 +12,26 @@ demoPeerToPeerScriptFunction();

function demoPeerToPeerScript() {
const address = hexToAccountAddress("0x00000000000000000000000000000001");
const token = new DiemTypes.TypeTagVariantStruct(
new DiemTypes.StructTag(
const token = new AptosTypes.TypeTagVariantStruct(
new AptosTypes.StructTag(
address,
new DiemTypes.Identifier("XDX"),
new DiemTypes.Identifier("XDX"),
new AptosTypes.Identifier("XDX"),
new AptosTypes.Identifier("XDX"),
[],
),
);

const payee = hexToAccountAddress("0x22222222222222222222222222222222");
const amount = BigInt(1_234_567);
const script = DiemStdlib.Stdlib.encodePeerToPeerWithMetadataScript(
const script = AptosStdlib.Stdlib.encodePeerToPeerWithMetadataScript(
token,
payee,
amount,
new Uint8Array(),
new Uint8Array(),
);

const scriptCall = DiemStdlib.Stdlib.decodePeerToPeerWithMetadataScript(
const scriptCall = AptosStdlib.Stdlib.decodePeerToPeerWithMetadataScript(
script,
);
if (scriptCall.amount != amount || scriptCall.payee != payee) {
Expand All @@ -48,26 +48,26 @@ function demoPeerToPeerScript() {

function demoPeerToPeerScriptFunction() {
const address = hexToAccountAddress("0x00000000000000000000000000000001");
const token = new DiemTypes.TypeTagVariantStruct(
new DiemTypes.StructTag(
const token = new AptosTypes.TypeTagVariantStruct(
new AptosTypes.StructTag(
address,
new DiemTypes.Identifier("XDX"),
new DiemTypes.Identifier("XDX"),
new AptosTypes.Identifier("XDX"),
new AptosTypes.Identifier("XDX"),
[],
),
);

const payee = hexToAccountAddress("0x22222222222222222222222222222222");
const amount = BigInt(1_234_567);
const payload = DiemStdlib.Stdlib.encodePeerToPeerWithMetadataScriptFunction(
const payload = AptosStdlib.Stdlib.encodePeerToPeerWithMetadataScriptFunction(
token,
payee,
amount,
new Uint8Array(),
new Uint8Array(),
);

const scriptFunCall = DiemStdlib.Stdlib.decodePeerToPeerWithMetadataScriptFunction(
const scriptFunCall = AptosStdlib.Stdlib.decodePeerToPeerWithMetadataScriptFunction(
payload,
);
if (scriptFunCall.amount != amount || !equal(scriptFunCall.payee.value, payee.value)) {
Expand All @@ -82,15 +82,15 @@ function demoPeerToPeerScriptFunction() {
console.log(bcsSerializer.getBytes().join(" ") + " ");
}

function hexToAccountAddress(hex: string): DiemTypes.AccountAddress {
function hexToAccountAddress(hex: string): AptosTypes.AccountAddress {
if (hex.startsWith("0x")) {
hex = hex.slice(2);
}
const senderListTuple: ListTuple<[number]> = [];
for (const entry of hexToBytes(hex)) { // encode as bytes
senderListTuple.push([entry]);
}
return new DiemTypes.AccountAddress(senderListTuple);
return new AptosTypes.AccountAddress(senderListTuple);
}

function hexToBytes(hex: string) {
Expand Down
16 changes: 8 additions & 8 deletions aptos-move/transaction-builder-generator/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn write_script_call_files(
namespace_name: &str,
abis: &[ScriptABI],
) -> Result<()> {
let external_definitions = crate::common::get_external_definitions("Diem.Types");
let external_definitions = crate::common::get_external_definitions("Aptos.Types");
let (transaction_script_abis, script_fun_abis): (Vec<_>, Vec<_>) = abis
.iter()
.cloned()
Expand Down Expand Up @@ -181,7 +181,7 @@ using System.Collections;
using System.Collections.Generic; // For List, Dictonary
using System.Numerics; // For BigInteger
using Bcs;
using Diem.Types; // For Script, TransactionArgument, VecBytes, TypeTag, TransactionPayload, ScriptFunction
using Aptos.Types; // For Script, TransactionArgument, VecBytes, TypeTag, TransactionPayload, ScriptFunction
using Serde; // For ValueArray (e.g., ValueArray<byte>)
"#,
)?;
Expand All @@ -194,7 +194,7 @@ using Serde; // For ValueArray (e.g., ValueArray<byte>)
self.out,
r#"
/// <summary>
/// Build a Diem Script from a structured value {{@link ScriptCall}}.
/// Build a Aptos Script from a structured value {{@link ScriptCall}}.
/// </summary>
/// <returns>
/// Encoded Script
Expand All @@ -210,7 +210,7 @@ public static Script EncodeScript(ScriptCall call) {{
self.out,
r#"
/// <summary>
/// Build a Diem Transaction Script from a structured value {{@link ScriptFunctionCall}}.
/// Build a Aptos Transaction Script from a structured value {{@link ScriptFunctionCall}}.
/// </summary>
/// <returns>
/// Encoded TransactionPayload holding a ScriptFunction
Expand All @@ -228,7 +228,7 @@ public static TransactionPayload EncodeScriptFunction(ScriptFunctionCall call) {
self.out,
r#"
/// <summary>
/// Try to recognize a Diem Script and convert it into a structured value Script.
/// Try to recognize a Aptos Script and convert it into a structured value Script.
/// </summary>
/// <returns>
/// Decoded ScriptCall value
Expand All @@ -248,7 +248,7 @@ public static ScriptCall DecodeScript(Script script) {{
self.out,
r#"
/// <summary>
/// Try to recognize a Diem TransactionPayload holding a ScriptFunction and convert it into a structured value ScriptFunction.
/// Try to recognize a Aptos TransactionPayload holding a ScriptFunction and convert it into a structured value ScriptFunction.
/// </summary>
/// <returns>
/// Decoded ScriptFunctionCall value
Expand Down Expand Up @@ -330,7 +330,7 @@ public static ScriptFunctionCall DecodeScriptFunctionPayload(TransactionPayload
Self::quote_doc(
abi.doc(),
[quoted_type_params_doc, quoted_params_doc].concat(),
"Encoded Diem.Types.Script value.",
"Encoded Aptos.Types.Script value.",
),
abi.name(),
[quoted_type_params, quoted_params].concat().join(", ")
Expand Down Expand Up @@ -367,7 +367,7 @@ return new Script(
Self::quote_doc(
abi.doc(),
[quoted_type_params_doc, quoted_params_doc].concat(),
"Encoded Diem.Types.TransactionPayload value holding a ScriptFunction.",
"Encoded Aptos.Types.TransactionPayload value holding a ScriptFunction.",
),
abi.name(),
[quoted_type_params, quoted_params].concat().join(", ")
Expand Down
Loading

0 comments on commit 8ed58a3

Please sign in to comment.