Skip to content

Commit

Permalink
Merge pull request #29 from radixdlt/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
0xOmarA committed Feb 21, 2023
2 parents e794028 + 0e9b044 commit 295c8d1
Show file tree
Hide file tree
Showing 17 changed files with 4,489 additions and 24 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,11 @@ jobs:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Sanity Check no. 1
run: |
echo ${{ github.sha }}
- name: Checkout
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: Sanity Check no. 2
run: |
ls -laR ./artifacts/
- name: Extract Artifacts
working-directory: artifacts
run: |
Expand All @@ -208,31 +202,28 @@ jobs:
mkdir "$fn"
tar -xvzf "$f" --directory="$fn";
done
- name: Sanity Check no. 3
run: |
ls -laR ./artifacts/
- name: Setup .NET SDK
uses: actions/setup-dotnet@5a3fa01c67e60dba8f95e2878436c7151c4b5f01
with:
dotnet-version: 7.0.x
- name: Configure Version # TODO missing support for stable packages on releases (where VERSION_SUFFIX should not be appended)
- name: Configure Version
run: |
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/\//-/g')
GIT_COMMIT=$(git log -1 --format=%h )
CORE_VERSION=$(cat radix-engine-toolkit/Cargo.toml | grep -e '^version' | cut -d'"' -f 2)
VERSION_SUFFIX=${GIT_BRANCH}-${GIT_COMMIT}
VERSION=${CORE_VERSION}-${VERSION_SUFFIX}
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
VERSION=${CORE_VERSION}
fi
sed -i "s/\(<version>\)[^<>]*\(<\/version>\)/\1$VERSION\2/g" interop/csharp/RadixDlt.RadixEngineToolkit.Native.nuspec
echo "Configured Version: $VERSION"
- name: NuGet Pack
working-directory: interop/csharp
run: nuget pack
- name: Sanity Check no. 4
run: |
md5sum ./artifacts/native/aarch64-apple-darwin/libradix_engine_toolkit.dylib
md5sum ./interop/csharp/RadixDlt.RadixEngineToolkit.Native.nuspec
- name: Publish Packages
working-directory: interop/csharp
run: dotnet nuget push RadixDlt.RadixEngineToolkit.Native.*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }}
2 changes: 1 addition & 1 deletion native-json-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "native-json-interface"
version = "0.8.0"
version = "0.8.1"
edition = "2021"

[dependencies]
Expand Down
4 changes: 4 additions & 0 deletions native-json-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub mod native {
export_handler!(InformationHandler as information);

export_handler!(ConvertManifestHandler as convert_manifest);
export_handler!(AnalyzeManifestHandler as analyze_manifest);

export_handler!(CompileTransactionIntentHandler as compile_transaction_intent);
export_handler!(CompileSignedTransactionIntentHandler as compile_signed_transaction_intent);
Expand Down Expand Up @@ -167,6 +168,9 @@ pub mod jni {
export_handler!(
ConvertManifestHandler as Java_com_radixdlt_toolkit_RadixEngineToolkitFFI_convertManifest
);
export_handler!(
AnalyzeManifestHandler as Java_com_radixdlt_toolkit_RadixEngineToolkitFFI_analyzeManifest
);

export_handler!(
CompileTransactionIntentHandler
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-toolkit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-engine-toolkit"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
build = "build.rs"

Expand Down
8 changes: 4 additions & 4 deletions radix-engine-toolkit/src/model/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashSet;
use std::collections::BTreeSet;

use crate::address::Bech32Coder;
use crate::error::Result;
Expand Down Expand Up @@ -115,7 +115,7 @@ pub enum Instruction {

/// The non-fungible ids to take from the worktop. This is a set (serialized as a JSON
/// array) of `NonFungibleLocalId`s from the Value model.
#[schemars(with = "HashSet<crate::model::address::NonFungibleLocalId>")]
#[schemars(with = "BTreeSet<crate::model::address::NonFungibleLocalId>")]
ids: Vec<Value>,

/// A bucket to put the taken resources into. This field is serialized as a `Bucket` from
Expand Down Expand Up @@ -157,7 +157,7 @@ pub enum Instruction {

/// The non-fungible ids of the resource to assert their existence in the worktop. This is
/// a set (serialized as a JSON array) of `NonFungibleLocalId`s from the Value model.
#[schemars(with = "HashSet<crate::model::address::NonFungibleLocalId>")]
#[schemars(with = "BTreeSet<crate::model::address::NonFungibleLocalId>")]
ids: Vec<Value>,
},

Expand Down Expand Up @@ -216,7 +216,7 @@ pub enum Instruction {

/// The non-fungible ids to create a proof of. This is a set (serialized as a JSON array)
/// of `NonFungibleLocalId`s from the Value model.
#[schemars(with = "HashSet<crate::model::address::NonFungibleLocalId>")]
#[schemars(with = "BTreeSet<crate::model::address::NonFungibleLocalId>")]
ids: Vec<Value>,

/// A proof to put the resource proof into. This field is serialized as a `Proof` from the
Expand Down
201 changes: 201 additions & 0 deletions radix-engine-toolkit/src/request/analyze_manifest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use std::collections::BTreeSet;

use crate::error::Result;
use crate::model::instruction_list::InstructionKind;
use crate::model::TransactionManifest;
use crate::{
traverse_instruction, AccountInteractionsInstructionVisitor, AddressValueAggregator,
ConvertManifestHandler, Handler, Instruction, InstructionList, NetworkAwareComponentAddress,
NetworkAwarePackageAddress, NetworkAwareResourceAddress, ValueNetworkAggregatorVisitor,
};
use scrypto::prelude::ComponentAddress;
use serializable::serializable;

// =================
// Model Definition
// =================

/// Analyzes the passed manifest to determine the entities that this manifest interacts with.
#[serializable]
pub struct AnalyzeManifestRequest {
/// An unsigned 8 bit integer serialized as a string which represents the ID of the network
/// that the manifest will be used on. The primary use of this is for any Bech32m encoding
/// or decoding of addresses
#[schemars(with = "String")]
#[schemars(regex(pattern = "[0-9]+"))]
#[serde_as(as = "serde_with::DisplayFromStr")]
pub network_id: u8,

/// The manifest to convert to the format described by `instructions_output_kind`
pub manifest: TransactionManifest,
}

/// The response of the [`AnalyzeManifestRequest`]
#[serializable]
pub struct AnalyzeManifestResponse {
/// A set of all of the package addresses seen in the manifest. The underlying type of this is
/// an array of `PackageAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub package_addresses: BTreeSet<NetworkAwarePackageAddress>,

/// A set of all of the component addresses seen in the manifest. The underlying type of this
/// is an array of `ComponentAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub component_addresses: BTreeSet<NetworkAwareComponentAddress>,

/// A set of all of the resource addresses seen in the manifest. The underlying type of this is
/// an array of `ResourceAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub resource_addresses: BTreeSet<NetworkAwareResourceAddress>,

/// A set of all of the account component addresses seen in the manifest. The underlying type
/// of this is an array of `ComponentAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub account_addresses: BTreeSet<NetworkAwareComponentAddress>,

/// A set of all of the account component addresses in the manifest which had methods invoked
/// on them that would typically require auth (or a signature) to be called successfully.
/// This is a subset of the addresses seen in `account_addresses`. The underlying type of
/// this is an array of `ComponentAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub accounts_requiring_auth: BTreeSet<NetworkAwareComponentAddress>,

/// A set of all of the account component addresses in the manifest which were withdrawn from.
/// This is a subset of the addresses seen in `account_addresses`. The underlying type of this
/// is an array of `ComponentAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub accounts_withdrawn_from: BTreeSet<NetworkAwareComponentAddress>,

/// A set of all of the account component addresses in the manifest which were deposited into.
/// This is a subset of the addresses seen in `account_addresses`. The underlying type of this
/// is an array of `ComponentAddress`es from the `Value` model.
#[schemars(with = "BTreeSet<crate::model::Value>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<crate::model::Value>>")]
pub accounts_deposited_into: BTreeSet<NetworkAwareComponentAddress>,
}

// ===============
// Implementation
// ===============

pub struct AnalyzeManifestHandler;

impl Handler<AnalyzeManifestRequest, AnalyzeManifestResponse> for AnalyzeManifestHandler {
fn pre_process(mut request: AnalyzeManifestRequest) -> Result<AnalyzeManifestRequest> {
// Visitors
let mut network_aggregator_visitor = ValueNetworkAggregatorVisitor::default();

// Instructions
let instructions: &mut [Instruction] = match request.manifest.instructions {
InstructionList::Parsed(ref mut instructions) => instructions,
InstructionList::String(..) => &mut [],
};

// Traverse instructions with visitors
instructions
.iter_mut()
.map(|instruction| {
traverse_instruction(instruction, &mut [&mut network_aggregator_visitor], &mut [])
})
.collect::<Result<Vec<_>>>()?;

// Check for network mismatches
if let Some(network_id) = network_aggregator_visitor
.0
.iter()
.find(|network_id| **network_id != request.network_id)
{
return Err(crate::Error::NetworkMismatchError {
found: *network_id,
expected: request.network_id,
});
}
Ok(request)
}

fn handle(request: &AnalyzeManifestRequest) -> Result<AnalyzeManifestResponse> {
// Getting the instructions in the passed manifest as parsed instructions
let mut instructions = {
let manifest = ConvertManifestHandler::fulfill(crate::ConvertManifestRequest {
network_id: request.network_id,
instructions_output_kind: InstructionKind::Parsed,
manifest: request.manifest.clone(),
})?
.manifest;

match manifest.instructions {
InstructionList::Parsed(instructions) => Ok(instructions),
InstructionList::String(..) => Err(crate::error::Error::Infallible {
message: "Impossible Case! We converted to parsed but it's still a string!"
.into(),
}),
}
}?;

// Setting up the visitors and traversing the instructions
let mut address_aggregator_visitor = AddressValueAggregator::default();
let mut account_interactions_visitor = AccountInteractionsInstructionVisitor::default();
instructions
.iter_mut()
.map(|instruction| {
traverse_instruction(
instruction,
&mut [&mut address_aggregator_visitor],
&mut [&mut account_interactions_visitor],
)
})
.collect::<Result<Vec<_>>>()?;

let response = AnalyzeManifestResponse {
package_addresses: address_aggregator_visitor.package_addresses,
resource_addresses: address_aggregator_visitor.resource_addresses,
component_addresses: address_aggregator_visitor.component_addresses.clone(),
account_addresses: address_aggregator_visitor
.component_addresses
.into_iter()
.filter(|address| {
matches!(
address.address,
ComponentAddress::Account(..)
| ComponentAddress::EcdsaSecp256k1VirtualAccount(..)
| ComponentAddress::EddsaEd25519VirtualAccount(..)
)
})
.collect(),
accounts_requiring_auth: account_interactions_visitor.auth_required,
accounts_withdrawn_from: account_interactions_visitor.accounts_withdrawn_from,
accounts_deposited_into: account_interactions_visitor.accounts_deposited_into,
};
Ok(response)
}

fn post_process(
_: &AnalyzeManifestRequest,
response: AnalyzeManifestResponse,
) -> Result<AnalyzeManifestResponse> {
Ok(response)
}
}
2 changes: 2 additions & 0 deletions radix-engine-toolkit/src/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ pub mod derive_non_fungible_global_id_from_public_key;
pub mod derive_virtual_account_address;
pub mod derive_virtual_identity_address;

pub mod analyze_manifest;
pub mod known_entity_addresses;
pub mod statically_validate_transaction;

pub mod traits;

pub use analyze_manifest::*;
pub use compile_notarized_transaction::*;
pub use compile_signed_transaction_intent::*;
pub use compile_transaction_intent::*;
Expand Down
Loading

0 comments on commit 295c8d1

Please sign in to comment.