Script opcode and data support

Overrides the shift-left operator for pushing opcodes onto the Script,
matching the notation used in zcashd.
This commit is contained in:
Jack Grigg
2019-07-27 00:28:00 +01:00
parent 1862354ea6
commit dab3c002b7
5 changed files with 111 additions and 21 deletions
+1 -15
View File
@@ -7,7 +7,7 @@ use sapling_crypto::{
};
use std::io::{self, Read, Write};
use serialize::Vector;
use legacy::Script;
use JUBJUB;
// π_A + π_B + π_C
@@ -58,20 +58,6 @@ impl Amount {
}
}
#[derive(Debug)]
pub struct Script(pub Vec<u8>);
impl Script {
pub fn read<R: Read>(mut reader: R) -> io::Result<Self> {
let script = Vector::read(&mut reader, |r| r.read_u8())?;
Ok(Script(script))
}
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
Vector::write(&mut writer, &self.0, |w, e| w.write_u8(*e))
}
}
#[derive(Debug)]
pub struct OutPoint {
hash: [u8; 32],
+2 -1
View File
@@ -3,10 +3,11 @@ use byteorder::{LittleEndian, WriteBytesExt};
use ff::{PrimeField, PrimeFieldRepr};
use super::{
components::{Amount, Script, TxOut},
components::{Amount, TxOut},
Transaction, TransactionData, OVERWINTER_VERSION_GROUP_ID, SAPLING_TX_VERSION,
SAPLING_VERSION_GROUP_ID,
};
use legacy::Script;
const ZCASH_SIGHASH_PERSONALIZATION_PREFIX: &'static [u8; 12] = b"ZcashSigHash";
const ZCASH_PREVOUTS_HASH_PERSONALIZATION: &'static [u8; 16] = b"ZcashPrevoutHash";
+2 -5
View File
@@ -6,11 +6,8 @@ use sapling_crypto::{
redjubjub::PrivateKey,
};
use super::{
components::{Amount, Script},
sighash::signature_hash,
Transaction, TransactionData,
};
use super::{components::Amount, sighash::signature_hash, Transaction, TransactionData};
use legacy::Script;
use JUBJUB;
#[test]