Skip to content

Commit

Permalink
Merge ad20d40 into 53520c1
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed Aug 7, 2019
2 parents 53520c1 + ad20d40 commit 3144fb6
Show file tree
Hide file tree
Showing 40 changed files with 206 additions and 182 deletions.
4 changes: 2 additions & 2 deletions cli/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
ink_core = { git = "https://github.com/paritytech/ink", package = "ink_core", default-features = false }
ink_model = { git = "https://github.com/paritytech/ink", package = "ink_model", default-features = false }
ink_lang = { git = "https://github.com/paritytech/ink", package = "ink_lang", default-features = false }
parity-codec = { version = "4.1", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "1.0", default-features = false, features = ["derive"] }

[lib]
name = "{{name}}"
Expand All @@ -20,7 +20,7 @@ std = [
"ink_core/std",
"ink_model/std",
"ink_lang/std",
"parity-codec/std",
"parity-scale-codec/std",
]
test-env = [
"std",
Expand Down
4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]
[dependencies]
ink_alloc = { path = "../alloc/", default-features = false }
ink_utils = { path = "../utils/", default-features = false }
parity-codec = { version = "4.1", default-features = false, features = ["derive", "full"] }
parity-scale-codec = { version = "1.0", default-features = false, features = ["derive", "full"] }

[features]
default = ["std"]
test-env = ["std"]
std = [
"ink_alloc/std",
"ink_utils/std",
"parity-codec/std",
"parity-scale-codec/std",
]
2 changes: 1 addition & 1 deletion core/src/env/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
memory::vec::Vec,
storage::Key,
};
use parity_codec::Encode;
use parity_scale_codec::Encode;

/// Stores the given value under the specified key in the contract storage.
///
Expand Down
5 changes: 1 addition & 4 deletions core/src/env/srml/srml_only/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
storage::Key,
};
use core::marker::PhantomData;
use parity_codec::Decode;
use parity_scale_codec::Decode;

/// Load the contents of the scratch buffer
fn read_scratch_buffer() -> Vec<u8> {
Expand Down Expand Up @@ -95,9 +95,6 @@ macro_rules! impl_getters_for_srml_env {
fn $name() -> $ret_type {
unsafe { sys::$ext_name() };
Decode::decode(&mut &read_scratch_buffer()[..])
.ok_or(concat!(
stringify!($name), " received an incorrectly sized buffer from SRML"
))
.expect(concat!(
stringify!($name), " expects to receive a correctly sized buffer"
))
Expand Down
8 changes: 4 additions & 4 deletions core/src/env/srml/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
impl_empty_flush_for,
storage::Flush,
};
use parity_codec::{
use parity_scale_codec::{
Decode,
Encode,
};
Expand All @@ -44,14 +44,14 @@ pub enum DefaultSrmlTypes {}
/// environment, in order to keep the code size small.
#[cfg_attr(feature = "test-env", derive(Debug, Clone, PartialEq, Eq))]
pub enum Call {}
impl parity_codec::Encode for Call {}
impl parity_scale_codec::Encode for Call {}

/// This implementation is only to satisfy the Decode constraint in the
/// test environment. Since Call cannot be constructed then just return
/// None, but this should never be called.
#[cfg(feature = "test-env")]
impl parity_codec::Decode for Call {
fn decode<I: parity_codec::Input>(_value: &mut I) -> Option<Self> {
impl parity_scale_codec::Decode for Call {
fn decode<I: parity_scale_codec::Input>(_value: &mut I) -> Option<Self> {
None
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/env/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use core::cell::{
Cell,
RefCell,
};
use parity_codec::{
use parity_scale_codec::{
Decode,
Encode,
};
Expand Down
4 changes: 2 additions & 2 deletions core/src/env/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
memory::vec::Vec,
storage::Key,
};
use parity_codec::Codec;
use parity_scale_codec::Codec;

#[cfg(not(feature = "test-env"))]
/// The environmental types usable by contracts defined with ink!.
Expand All @@ -34,7 +34,7 @@ pub trait EnvTypes {
/// The type of block number.
type BlockNumber: Codec + Clone + PartialEq + Eq;
/// The type of a call into the runtime
type Call: parity_codec::Encode;
type Call: parity_scale_codec::Encode;
}

#[cfg(feature = "test-env")]
Expand Down
2 changes: 1 addition & 1 deletion core/src/storage/alloc/cc_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::storage::{
Key,
};

use parity_codec::{
use parity_scale_codec::{
Decode,
Encode,
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/storage/cell/raw_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
},
};

use parity_codec::{
use parity_scale_codec::{
Decode,
Encode,
};
Expand Down
18 changes: 10 additions & 8 deletions core/src/storage/cell/sync_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,16 @@ impl<T> Cache<T> {
}
}

impl<T> parity_codec::Encode for SyncCell<T> {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
impl<T> parity_scale_codec::Encode for SyncCell<T> {
fn encode_to<W: parity_scale_codec::Output>(&self, dest: &mut W) {
self.cell.encode_to(dest)
}
}

impl<T> parity_codec::Decode for SyncCell<T> {
fn decode<I: parity_codec::Input>(input: &mut I) -> Option<Self> {
impl<T> parity_scale_codec::Decode for SyncCell<T> {
fn decode<I: parity_scale_codec::Input>(
input: &mut I,
) -> Result<Self, parity_scale_codec::Error> {
TypedCell::decode(input).map(|typed_cell| {
Self {
cell: typed_cell,
Expand All @@ -305,7 +307,7 @@ impl<T> parity_codec::Decode for SyncCell<T> {

impl<T> Flush for SyncCell<T>
where
T: parity_codec::Encode + Flush,
T: parity_scale_codec::Encode + Flush,
{
fn flush(&mut self) {
if self.cache.is_dirty() {
Expand Down Expand Up @@ -343,7 +345,7 @@ impl<T> SyncCell<T> {

impl<T> SyncCell<T>
where
T: parity_codec::Decode,
T: parity_scale_codec::Decode,
{
/// Returns an immutable reference to the value of the cell.
pub fn get(&self) -> Option<&T> {
Expand All @@ -357,7 +359,7 @@ where

impl<T> SyncCell<T>
where
T: parity_codec::Encode,
T: parity_scale_codec::Encode,
{
/// Sets the value of the cell.
pub fn set(&mut self, val: T) {
Expand All @@ -368,7 +370,7 @@ where

impl<T> SyncCell<T>
where
T: parity_codec::Codec,
T: parity_scale_codec::Codec,
{
/// Returns a mutable reference to the value of the cell.
pub fn get_mut(&mut self) -> Option<&mut T> {
Expand Down
23 changes: 14 additions & 9 deletions core/src/storage/cell/typed_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ pub struct TypedCell<T> {
non_clone: NonCloneMarker<T>,
}

impl<T> parity_codec::Encode for TypedCell<T> {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
impl<T> parity_scale_codec::Encode for TypedCell<T> {
fn encode_to<W: parity_scale_codec::Output>(&self, dest: &mut W) {
self.cell.encode_to(dest)
}
}

impl<T> parity_codec::Decode for TypedCell<T> {
fn decode<I: parity_codec::Input>(input: &mut I) -> Option<Self> {
impl<T> parity_scale_codec::Decode for TypedCell<T> {
fn decode<I: parity_scale_codec::Input>(
input: &mut I,
) -> Result<Self, parity_scale_codec::Error> {
RawCell::decode(input).map(|raw_cell| {
Self {
cell: raw_cell,
Expand Down Expand Up @@ -79,19 +81,22 @@ impl<T> TypedCell<T> {

impl<T> TypedCell<T>
where
T: parity_codec::Decode,
T: parity_scale_codec::Decode,
{
/// Loads the value stored in the cell if any.
pub fn load(&self) -> Option<T> {
self.cell
.load()
.and_then(|bytes| T::decode(&mut &bytes[..]))
self.cell.load().map(|bytes| {
T::decode(&mut &bytes[..]).expect(
"[ink_core::TypedCell::load] Error: \
failed upon decoding",
)
})
}
}

impl<T> TypedCell<T>
where
T: parity_codec::Encode,
T: parity_scale_codec::Encode,
{
/// Stores the value into the cell.
pub fn store(&mut self, val: &T) {
Expand Down
10 changes: 6 additions & 4 deletions core/src/storage/chunk/raw_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ impl RawChunkCell<'_> {
}
}

impl parity_codec::Encode for RawChunk {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
impl parity_scale_codec::Encode for RawChunk {
fn encode_to<W: parity_scale_codec::Output>(&self, dest: &mut W) {
self.key.encode_to(dest)
}
}

impl parity_codec::Decode for RawChunk {
fn decode<I: parity_codec::Input>(input: &mut I) -> Option<Self> {
impl parity_scale_codec::Decode for RawChunk {
fn decode<I: parity_scale_codec::Input>(
input: &mut I,
) -> Result<Self, parity_scale_codec::Error> {
Key::decode(input).map(|key| unsafe { Self::new_unchecked(key) })
}
}
Expand Down
18 changes: 10 additions & 8 deletions core/src/storage/chunk/sync_chunk/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct SyncChunk<T> {

impl<T> Flush for SyncChunk<T>
where
T: parity_codec::Encode + Flush,
T: parity_scale_codec::Encode + Flush,
{
fn flush(&mut self) {
for (n, dirty_val) in self.cache.iter_dirty() {
Expand All @@ -63,14 +63,16 @@ where
}
}

impl<T> parity_codec::Encode for SyncChunk<T> {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
impl<T> parity_scale_codec::Encode for SyncChunk<T> {
fn encode_to<W: parity_scale_codec::Output>(&self, dest: &mut W) {
self.chunk.encode_to(dest)
}
}

impl<T> parity_codec::Decode for SyncChunk<T> {
fn decode<I: parity_codec::Input>(input: &mut I) -> Option<Self> {
impl<T> parity_scale_codec::Decode for SyncChunk<T> {
fn decode<I: parity_scale_codec::Input>(
input: &mut I,
) -> Result<Self, parity_scale_codec::Error> {
TypedChunk::decode(input).map(|typed_chunk| {
Self {
chunk: typed_chunk,
Expand Down Expand Up @@ -111,7 +113,7 @@ impl<T> SyncChunk<T> {

impl<T> SyncChunk<T>
where
T: parity_codec::Decode,
T: parity_scale_codec::Decode,
{
/// Returns the value of the `n`-th cell if any.
#[must_use]
Expand Down Expand Up @@ -152,7 +154,7 @@ where

impl<T> SyncChunk<T>
where
T: parity_codec::Encode,
T: parity_scale_codec::Encode,
{
/// Sets the value of the `n`-th cell.
pub fn set(&mut self, n: u32, val: T) {
Expand All @@ -162,7 +164,7 @@ where

impl<T> SyncChunk<T>
where
T: parity_codec::Codec,
T: parity_scale_codec::Codec,
{
/// Replaces the value of the `n`-th cell and returns its old value if any.
///
Expand Down
16 changes: 9 additions & 7 deletions core/src/storage/chunk/typed_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@ impl<'a, T> TypedChunkCell<'a, T> {

impl<'a, T> TypedChunkCell<'a, T>
where
T: parity_codec::Encode,
T: parity_scale_codec::Encode,
{
/// Stores the value into the cell.
pub fn store(&mut self, val: &T) {
self.cell.store(&T::encode(val))
}
}

impl<T> parity_codec::Encode for TypedChunk<T> {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
impl<T> parity_scale_codec::Encode for TypedChunk<T> {
fn encode_to<W: parity_scale_codec::Output>(&self, dest: &mut W) {
self.chunk.encode_to(dest)
}
}

impl<T> parity_codec::Decode for TypedChunk<T> {
fn decode<I: parity_codec::Input>(input: &mut I) -> Option<Self> {
impl<T> parity_scale_codec::Decode for TypedChunk<T> {
fn decode<I: parity_scale_codec::Input>(
input: &mut I,
) -> Result<Self, parity_scale_codec::Error> {
RawChunk::decode(input).map(|raw_chunk| {
Self {
chunk: raw_chunk,
Expand Down Expand Up @@ -136,7 +138,7 @@ impl<T> TypedChunk<T> {

impl<T> TypedChunk<T>
where
T: parity_codec::Decode,
T: parity_scale_codec::Decode,
{
/// Loads the value stored in the `n`-th cell if any.
///
Expand All @@ -157,7 +159,7 @@ where

impl<T> TypedChunk<T>
where
T: parity_codec::Encode,
T: parity_scale_codec::Encode,
{
/// Stores the value into the `n`-th cell.
pub fn store(&mut self, n: u32, val: &T) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/storage/collections/bitvec/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use super::BitPack;
use crate::storage::Flush;
use parity_codec::{
use parity_scale_codec::{
Decode,
Encode,
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/storage/collections/bitvec/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with ink!. If not, see <http://www.gnu.org/licenses/>.

use parity_codec::{
use parity_scale_codec::{
Decode,
Encode,
};
Expand Down

0 comments on commit 3144fb6

Please sign in to comment.