Skip to content

Commit

Permalink
chore: remove asset lock proof type
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 20, 2023
1 parent ef38440 commit b7d8afc
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use dashcore::OutPoint;
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChainAssetLockProof {
// TODO: Remove type
#[serde(rename = "type")]
asset_lock_type: u8,
pub core_chain_locked_height: u32,
pub out_point: OutPoint,
}
Expand All @@ -36,18 +33,11 @@ impl ChainAssetLockProof {

pub fn new(core_chain_locked_height: u32, out_point: [u8; 36]) -> Self {
Self {
// TODO: change to const
asset_lock_type: 1,
core_chain_locked_height,
out_point: OutPoint::from(out_point),
}
}

/// Get proof type
pub fn asset_lock_type() -> u8 {
1
}

/// Create identifier
pub fn create_identifier(&self) -> Result<Identifier, ProtocolError> {
let mut outpoint_bytes = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use crate::ProtocolError;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InstantAssetLockProof {
// TODO: Remove type
asset_lock_type: u8,
instant_lock: InstantLock,
transaction: Transaction,
output_index: u32,
Expand Down Expand Up @@ -63,7 +61,6 @@ impl Default for InstantAssetLockProof {
fn default() -> Self {
Self {
// TODO: change to a const
asset_lock_type: 0,
instant_lock: InstantLock::default(),
transaction: Transaction {
version: 0,
Expand All @@ -80,25 +77,20 @@ impl Default for InstantAssetLockProof {
impl InstantAssetLockProof {
pub fn new(instant_lock: InstantLock, transaction: Transaction, output_index: u32) -> Self {
Self {
// TODO: change the type to a const
instant_lock,
transaction,
output_index,
asset_lock_type: 0,
}
}

pub fn to_object(&self) -> Result<Value, ProtocolError> {
platform_value::to_value(self).map_err(ProtocolError::ValueError)
}

pub fn to_cleaned_object(&self) -> Result<Value, ProtocolError> {
self.to_object()
}

pub fn asset_lock_type(&self) -> u8 {
self.asset_lock_type
}

pub fn instant_lock(&self) -> &InstantLock {
&self.instant_lock
}
Expand Down Expand Up @@ -156,7 +148,6 @@ impl InstantAssetLockProof {
.consensus_encode(&mut transaction_buffer)
.map_err(|e| ProtocolError::EncodingError(e.to_string()))?;

map.insert("type", self.asset_lock_type);
map.insert("outputIndex", self.output_index);
map.insert("transaction", transaction_buffer);
map.insert("instantLock", is_lock_buffer);
Expand Down Expand Up @@ -202,8 +193,6 @@ impl InstantAssetLockProof {
#[serde(rename_all = "camelCase")]
/// "Raw" instant lock for serialization
pub struct RawInstantLockProof {
#[serde(rename = "type")]
lock_type: u8,
instant_lock: BinaryData,
transaction: BinaryData,
output_index: u32,
Expand All @@ -219,7 +208,6 @@ impl TryFrom<RawInstantLockProof> for InstantAssetLockProof {
.map_err(|e| ProtocolError::DecodingError(e.to_string()))?;

Ok(Self {
asset_lock_type: raw_instant_lock.lock_type,
transaction,
instant_lock,
output_index: raw_instant_lock.output_index,
Expand All @@ -243,7 +231,6 @@ impl TryFrom<&InstantAssetLockProof> for RawInstantLockProof {
.map_err(|e| ProtocolError::EncodingError(e.to_string()))?;

Ok(Self {
lock_type: instant_asset_lock_proof.asset_lock_type,
instant_lock: BinaryData::new(is_lock_buffer),
transaction: BinaryData::new(transaction_buffer),
output_index: instant_asset_lock_proof.output_index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ impl ChainAssetLockProofWasm {
Ok(ChainAssetLockProofWasm(chain_asset_lock_proof))
}

#[wasm_bindgen(js_name=getType)]
pub fn get_type(&self) -> u8 {
ChainAssetLockProof::asset_lock_type()
}

#[wasm_bindgen(js_name=getCoreChainLockedHeight)]
pub fn get_core_chain_locked_height(&self) -> u32 {
self.0.core_chain_locked_height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ impl InstantAssetLockProofWasm {
Ok(instant_asset_lock_proof.into())
}

#[wasm_bindgen(js_name=getType)]
pub fn get_type(&self) -> u8 {
self.0.asset_lock_type()
}

#[wasm_bindgen(js_name=getOutputIndex)]
pub fn get_output_index(&self) -> usize {
self.0.output_index()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ describe('ChainAssetLockProof', () => {
);
});

describe('#getType', () => {
it('should return correct type', () => {
expect(chainAssetLockProof.getType())
.to.equal(chainAssetLockProofJS.getType());
});
});

describe('#getCoreChainLockedHeight', () => {
it('should return correct coreChainLockedHeight', () => {
expect(chainAssetLockProof.getCoreChainLockedHeight())
Expand Down

0 comments on commit b7d8afc

Please sign in to comment.