Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and remove GPL v3.0 from accepted licenses #537

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
799 changes: 456 additions & 343 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions about.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ accepted = [
"OpenSSL",
"Unicode-DFS-2016",
"NOASSERTION",
# Should be removed after #525 is fixed.
"GPL-3.0"
]
ignore-dev-dependencies = true
ignore-build-dependencies = true
10 changes: 5 additions & 5 deletions node-api/src/decoder/bit_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ pub fn get_bitsequence_details(
ty: &TypeDefBitSequence<PortableForm>,
types: &PortableRegistry,
) -> Result<(BitOrderTy, BitStoreTy), BitSequenceError> {
let bit_store_ty = ty.bit_store_type().id();
let bit_order_ty = ty.bit_order_type().id();
let bit_store_ty = ty.bit_store_type.id;
let bit_order_ty = ty.bit_order_type.id;

// What is the backing store type expected?
let bit_store_def = types
let bit_store_def = &types
.resolve(bit_store_ty)
.ok_or(BitSequenceError::BitStoreTypeNotFound(bit_store_ty))?
.type_def();
.type_def;

// What is the bit order type expected?
let bit_order_def = types
.resolve(bit_order_ty)
.ok_or(BitSequenceError::BitOrderTypeNotFound(bit_order_ty))?
.path()
.path
.ident()
.ok_or(BitSequenceError::NoBitOrderIdent)?;

Expand Down
42 changes: 21 additions & 21 deletions node-api/src/decoder/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn decode_value_as_type<Id: Into<TypeId>>(
.resolve(ty_id.id())
.ok_or_else(|| DecodeError::TypeIdNotFound(ty_id.id()))?;

let value = match ty.type_def() {
let value = match &ty.type_def {
TypeDef::Composite(inner) =>
decode_composite_value(data, inner, types).map(ValueDef::Composite),
TypeDef::Sequence(inner) =>
Expand All @@ -83,7 +83,7 @@ fn decode_composite_value(
ty: &TypeDefComposite<PortableForm>,
types: &PortableRegistry,
) -> Result<Composite<TypeId>, DecodeError> {
decode_fields(data, ty.fields(), types)
decode_fields(data, &ty.fields, types)
}

fn decode_variant_value(
Expand All @@ -96,13 +96,13 @@ fn decode_variant_value(

// Does a variant exist with the index we're looking for?
let variant = ty
.variants()
.variants
.iter()
.find(|v| v.index() == index)
.find(|v| v.index == index)
.ok_or_else(|| DecodeError::VariantNotFound(index, ty.clone()))?;

let fields = decode_fields(data, variant.fields(), types)?;
Ok(Variant { name: variant.name().clone(), values: fields })
let fields = decode_fields(data, &variant.fields, types)?;
Ok(Variant { name: variant.name.clone(), values: fields })
}

/// Variant and Composite types both have fields; this will decode them into values.
Expand All @@ -111,10 +111,10 @@ fn decode_fields(
fields: &[Field<PortableForm>],
types: &PortableRegistry,
) -> Result<Composite<TypeId>, DecodeError> {
let are_named = fields.iter().any(|f| f.name().is_some());
let are_named = fields.iter().any(|f| f.name.is_some());
let named_field_vals = fields.iter().map(|f| {
let name = f.name().cloned().unwrap_or_default();
decode_value_as_type(data, f.ty(), types).map(|val| (name, val))
let name = f.name.as_ref().cloned().unwrap_or_default();
decode_value_as_type(data, f.ty, types).map(|val| (name, val))
});

if are_named {
Expand All @@ -135,7 +135,7 @@ fn decode_sequence_value(
// we know how many values to try pulling out of the data.
let len = Compact::<u64>::decode(data)?;
let values: Vec<_> = (0..len.0)
.map(|_| decode_value_as_type(data, ty.type_param(), types))
.map(|_| decode_value_as_type(data, ty.type_param, types))
.collect::<Result<_, _>>()?;

Ok(Composite::Unnamed(values))
Expand All @@ -148,8 +148,8 @@ fn decode_array_value(
) -> Result<Composite<TypeId>, DecodeError> {
// The length is known based on the type we want to decode into, so we pull out the number of items according
// to that, and don't need a length to exist in the SCALE encoded bytes
let values: Vec<_> = (0..ty.len())
.map(|_| decode_value_as_type(data, ty.type_param(), types))
let values: Vec<_> = (0..ty.len)
.map(|_| decode_value_as_type(data, ty.type_param, types))
.collect::<Result<_, _>>()?;

Ok(Composite::Unnamed(values))
Expand All @@ -161,7 +161,7 @@ fn decode_tuple_value(
types: &PortableRegistry,
) -> Result<Composite<TypeId>, DecodeError> {
let values: Vec<_> = ty
.fields()
.fields
.iter()
.map(|f| decode_value_as_type(data, f, types))
.collect::<Result<_, _>>()?;
Expand Down Expand Up @@ -208,7 +208,7 @@ fn decode_compact_value(
types: &PortableRegistry,
) -> Result<ValueDef<TypeId>, DecodeError> {
use TypeDefPrimitive::*;
let val = match inner.type_def() {
let val = match &inner.type_def {
// It's obvious how to decode basic primitive unsigned types, since we have impls for them.
TypeDef::Primitive(U8) =>
ValueDef::Primitive(Primitive::uint(Compact::<u8>::decode(data)?.0)),
Expand All @@ -222,13 +222,13 @@ fn decode_compact_value(
ValueDef::Primitive(Primitive::uint(Compact::<u128>::decode(data)?.0)),
// A struct with exactly 1 field containing one of the above types can be sensibly compact encoded/decoded.
TypeDef::Composite(composite) => {
if composite.fields().len() != 1 {
if composite.fields.len() != 1 {
return Err(DecodeError::CannotDecodeCompactIntoType(inner.clone()))
}

// What type is the 1 field that we are able to decode?
let field = &composite.fields()[0];
let field_type_id = field.ty().id();
let field = &composite.fields[0];
let field_type_id = field.ty.id;
let inner_ty = types
.resolve(field_type_id)
.ok_or(DecodeError::TypeIdNotFound(field_type_id))?;
Expand All @@ -237,11 +237,11 @@ fn decode_compact_value(
// the inner type is also a 1-field composite type.
let inner_value = Value {
value: decode_compact(data, inner_ty, types)?,
context: field.ty().into(),
context: field.ty.into(),
};

// Wrap the inner type in a representation of this outer composite type.
let composite = match field.name() {
let composite = match &field.name {
Some(name) => Composite::Named(vec![(name.clone(), inner_value)]),
None => Composite::Unnamed(vec![inner_value]),
};
Expand All @@ -258,8 +258,8 @@ fn decode_compact_value(

// Pluck the inner type out and run it through our compact decoding logic.
let inner = types
.resolve(ty.type_param().id())
.ok_or_else(|| DecodeError::TypeIdNotFound(ty.type_param().id()))?;
.resolve(ty.type_param.id)
.ok_or_else(|| DecodeError::TypeIdNotFound(ty.type_param.id))?;
decode_compact(data, inner, types)
}

Expand Down
57 changes: 29 additions & 28 deletions node-api/src/decoder/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn encode_value_as_type<T, Id: Into<TypeId>>(
let ty_id = ty_id.into();
let ty = types.resolve(ty_id.id()).ok_or(EncodeError::TypeIdNotFound(ty_id))?;

match ty.type_def() {
match &ty.type_def {
TypeDef::Composite(inner) => encode_composite_value(value, ty_id, inner, types, bytes),
TypeDef::Sequence(inner) => encode_sequence_value(value, ty_id, inner, types, bytes),
TypeDef::Array(inner) => encode_array_value(value, ty_id, inner, types, bytes),
Expand All @@ -104,11 +104,11 @@ fn encode_composite_value<T>(
) -> Result<(), EncodeError<T>> {
match value.value {
ValueDef::Composite(composite) =>
encode_composite_fields(composite, ty.fields(), type_id, types, bytes),
encode_composite_fields(composite, &ty.fields, type_id, types, bytes),
_ => {
if ty.fields().len() == 1 {
if ty.fields.len() == 1 {
// A 1-field composite type? try encoding inner content then.
encode_value_as_type(value, ty.fields()[0].ty(), types, bytes)
encode_value_as_type(value, ty.fields[0].ty, types, bytes)
} else {
Err(EncodeError::WrongShape { actual: value, expected: type_id })
}
Expand All @@ -129,7 +129,7 @@ fn encode_sequence_value<T>(
ValueDef::Composite(c) => {
// Compact encoded length comes first
Compact(c.len() as u64).encode_to(bytes);
let ty = ty.type_param();
let ty = ty.type_param;
for value in c.into_values() {
encode_value_as_type(value, ty, types, bytes)?;
}
Expand All @@ -139,7 +139,7 @@ fn encode_sequence_value<T>(
ValueDef::Primitive(Primitive::I256(a) | Primitive::U256(a)) => {
// Compact encoded length comes first
Compact(a.len() as u64).encode_to(bytes);
let ty = ty.type_param();
let ty = ty.type_param;
for val in a {
if encode_value_as_type(Value::uint(val), ty, types, bytes).is_err() {
return Err(EncodeError::WrongShape { actual: value, expected: type_id })
Expand All @@ -162,7 +162,7 @@ fn encode_array_value<T>(
// Let's see whether our composite type is the right length,
// and try to encode each inner value into what the array wants.
ValueDef::Composite(c) => {
let arr_len = ty.len() as usize;
let arr_len = ty.len as usize;
if c.len() != arr_len {
return Err(EncodeError::CompositeIsWrongLength {
actual: c,
Expand All @@ -171,20 +171,20 @@ fn encode_array_value<T>(
})
}

let ty = ty.type_param();
let ty = ty.type_param;
for value in c.into_values() {
encode_value_as_type(value, ty, types, bytes)?;
}
},
// As a special case, primitive U256/I256s are arrays, and may be compatible
// with the array type being asked for, too.
ValueDef::Primitive(Primitive::I256(a) | Primitive::U256(a)) => {
let arr_len = ty.len() as usize;
let arr_len = ty.len as usize;
if a.len() != arr_len {
return Err(EncodeError::WrongShape { actual: value, expected: type_id })
}

let ty = ty.type_param();
let ty = ty.type_param;
for val in a {
if encode_value_as_type(Value::uint(val), ty, types, bytes).is_err() {
return Err(EncodeError::WrongShape { actual: value, expected: type_id })
Expand All @@ -205,25 +205,25 @@ fn encode_tuple_value<T>(
) -> Result<(), EncodeError<T>> {
match value.value {
ValueDef::Composite(composite) => {
if composite.len() != ty.fields().len() {
if composite.len() != ty.fields.len() {
return Err(EncodeError::CompositeIsWrongLength {
actual: composite,
expected: type_id,
expected_len: ty.fields().len(),
expected_len: ty.fields.len(),
})
}
// We don't care whether the fields are named or unnamed
// as long as we have the number of them that we expect..
let field_value_pairs = ty.fields().iter().zip(composite.into_values());
let field_value_pairs = ty.fields.iter().zip(composite.into_values());
for (ty, value) in field_value_pairs {
encode_value_as_type(value, ty, types, bytes)?;
}
Ok(())
},
_ => {
if ty.fields().len() == 1 {
if ty.fields.len() == 1 {
// A 1-field tuple? try encoding inner content then.
encode_value_as_type(value, ty.fields()[0], types, bytes)
encode_value_as_type(value, ty.fields[0], types, bytes)
} else {
Err(EncodeError::WrongShape { actual: value, expected: type_id })
}
Expand All @@ -243,15 +243,15 @@ fn encode_variant_value<T>(
_ => return Err(EncodeError::WrongShape { actual: value, expected: type_id }),
};

let variant_type = ty.variants().iter().find(|v| v.name() == &variant.name);
let variant_type = ty.variants.iter().find(|v| v.name == variant.name);

let variant_type = match variant_type {
None => return Err(EncodeError::VariantNotFound { actual: variant, expected: type_id }),
Some(v) => v,
};

variant_type.index().encode_to(bytes);
encode_composite_fields(variant.values, variant_type.fields(), type_id, types, bytes)
variant_type.index.encode_to(bytes);
encode_composite_fields(variant.values, &variant_type.fields, type_id, types, bytes)
}

fn encode_composite_fields<T>(
Expand All @@ -275,21 +275,21 @@ fn encode_composite_fields<T>(
}

// Does the type we're encoding to have named fields or not?
let is_named = fields[0].name().is_some();
let is_named = fields[0].name.is_some();

match (composite, is_named) {
(Composite::Named(mut values), true) => {
// Match up named values with those of the type we're encoding to.
for field in fields.iter() {
let field_name = field.name().expect("field should be named; checked above");
let field_name = field.name.as_ref().expect("field should be named; checked above");
let value = values
.iter()
.position(|(n, _)| field_name == n)
.map(|idx| values.swap_remove(idx).1);

match value {
Some(value) => {
encode_value_as_type(value, field.ty(), types, bytes)?;
encode_value_as_type(value, field.ty, types, bytes)?;
},
None =>
return Err(EncodeError::CompositeFieldIsMissing {
Expand All @@ -304,7 +304,7 @@ fn encode_composite_fields<T>(
(Composite::Unnamed(values), false) => {
// Expect values in correct order only and encode.
for (field, value) in fields.iter().zip(values) {
encode_value_as_type(value, field.ty(), types, bytes)?;
encode_value_as_type(value, field.ty, types, bytes)?;
}
Ok(())
},
Expand Down Expand Up @@ -426,23 +426,24 @@ fn encode_compact_value<T>(

// Resolve to a primitive type inside the compact encoded type (or fail if
// we hit some type we wouldn't know how to work with).
let mut inner_ty_id = ty.type_param().id();
let mut inner_ty_id = ty.type_param.id;
let inner_ty = loop {
let inner_ty = types
.resolve(inner_ty_id)
.ok_or_else(|| EncodeError::TypeIdNotFound(inner_ty_id.into()))?
.type_def();
.type_def
.clone();

match inner_ty {
TypeDef::Composite(c) =>
if c.fields().len() == 1 {
inner_ty_id = c.fields()[0].ty().id();
if c.fields.len() == 1 {
inner_ty_id = c.fields[0].ty.id;
} else {
return Err(EncodeError::CannotCompactEncode(inner_ty_id.into()))
},
TypeDef::Tuple(t) =>
if t.fields().len() == 1 {
inner_ty_id = t.fields()[0].id();
if t.fields.len() == 1 {
inner_ty_id = t.fields[0].id;
} else {
return Err(EncodeError::CannotCompactEncode(inner_ty_id.into()))
},
Expand Down
4 changes: 2 additions & 2 deletions node-api/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ impl Display for TypeId {

impl From<ScaleTypeId> for TypeId {
fn from(id: ScaleTypeId) -> Self {
TypeId(id.id())
TypeId(id.id)
}
}

impl From<&ScaleTypeId> for TypeId {
fn from(id: &ScaleTypeId) -> Self {
TypeId(id.id())
TypeId(id.id)
}
}

Expand Down
4 changes: 2 additions & 2 deletions node-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl DispatchError {
},
};

let variant = match dispatch_error_ty.type_def() {
let variant = match &dispatch_error_ty.type_def {
TypeDef::Variant(var) => var,
_ => {
warn!("Can't decode error: sp_runtime::DispatchError type is not a Variant");
Expand All @@ -116,7 +116,7 @@ impl DispatchError {
};

let module_variant_idx =
variant.variants().iter().find(|v| v.name() == "Module").map(|v| v.index());
variant.variants.iter().find(|v| v.name == "Module").map(|v| v.index);
let module_variant_idx = match module_variant_idx {
Some(idx) => idx,
None => {
Expand Down
Loading