Rename ScriptBuilder to Builder as per rustc rfc PR 1036
This commit is contained in:
parent
5350207ff3
commit
e658ffaeea
|
@ -23,7 +23,7 @@ use std::default::Default;
|
||||||
use std::num::from_u64;
|
use std::num::from_u64;
|
||||||
|
|
||||||
use blockdata::opcodes;
|
use blockdata::opcodes;
|
||||||
use blockdata::script::ScriptBuilder;
|
use blockdata::script;
|
||||||
use blockdata::transaction::{Transaction, TxOut, TxIn};
|
use blockdata::transaction::{Transaction, TxOut, TxIn};
|
||||||
use blockdata::block::{Block, BlockHeader};
|
use blockdata::block::{Block, BlockHeader};
|
||||||
use network::constants::Network;
|
use network::constants::Network;
|
||||||
|
@ -60,7 +60,7 @@ fn bitcoin_genesis_tx() -> Transaction {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Inputs
|
// Inputs
|
||||||
let mut in_script = ScriptBuilder::new();
|
let mut in_script = script::Builder::new();
|
||||||
in_script.push_scriptint(486604799);
|
in_script.push_scriptint(486604799);
|
||||||
in_script.push_scriptint(4);
|
in_script.push_scriptint(4);
|
||||||
in_script.push_slice("The Times 03/Jan/2009 Chancellor on brink of second bailout for banks".as_bytes());
|
in_script.push_slice("The Times 03/Jan/2009 Chancellor on brink of second bailout for banks".as_bytes());
|
||||||
|
@ -72,7 +72,7 @@ fn bitcoin_genesis_tx() -> Transaction {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Outputs
|
// Outputs
|
||||||
let mut out_script = ScriptBuilder::new();
|
let mut out_script = script::Builder::new();
|
||||||
out_script.push_slice(hex_bytes("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f").unwrap().as_slice());
|
out_script.push_slice(hex_bytes("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f").unwrap().as_slice());
|
||||||
out_script.push_opcode(opcodes::All::OP_CHECKSIG);
|
out_script.push_opcode(opcodes::All::OP_CHECKSIG);
|
||||||
ret.output.push(TxOut {
|
ret.output.push(TxOut {
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl Clone for Script {
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Display)]
|
#[derive(PartialEq, Eq, Debug, Clone, Display)]
|
||||||
/// An object which can be used to construct a script piece by piece
|
/// An object which can be used to construct a script piece by piece
|
||||||
pub struct ScriptBuilder(Vec<u8>);
|
pub struct Builder(Vec<u8>);
|
||||||
|
|
||||||
impl hash::Hash for Script {
|
impl hash::Hash for Script {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1975,7 +1975,7 @@ impl Script {
|
||||||
// Compute the section of script that needs to be hashed: everything
|
// Compute the section of script that needs to be hashed: everything
|
||||||
// from the last CODESEPARATOR, except the signature itself.
|
// from the last CODESEPARATOR, except the signature itself.
|
||||||
let mut script = (&self.0[codeseparator_index..]).to_vec();
|
let mut script = (&self.0[codeseparator_index..]).to_vec();
|
||||||
let mut remove = ScriptBuilder::new();
|
let mut remove = Builder::new();
|
||||||
remove.push_slice(sig_slice);
|
remove.push_slice(sig_slice);
|
||||||
script_find_and_remove(&mut script, &remove[..]);
|
script_find_and_remove(&mut script, &remove[..]);
|
||||||
// Also all of the OP_CODESEPARATORS, even the unevaluated ones
|
// Also all of the OP_CODESEPARATORS, even the unevaluated ones
|
||||||
|
@ -2026,7 +2026,7 @@ impl Script {
|
||||||
// from the last CODESEPARATOR, except the signatures themselves.
|
// from the last CODESEPARATOR, except the signatures themselves.
|
||||||
let mut script = (&self.0[codeseparator_index..]).to_vec();
|
let mut script = (&self.0[codeseparator_index..]).to_vec();
|
||||||
for sig in sigs.iter() {
|
for sig in sigs.iter() {
|
||||||
let mut remove = ScriptBuilder::new();
|
let mut remove = Builder::new();
|
||||||
remove.push_slice(&sig[..]);
|
remove.push_slice(&sig[..]);
|
||||||
script_find_and_remove(&mut script, &remove[..]);
|
script_find_and_remove(&mut script, &remove[..]);
|
||||||
script_find_and_remove(&mut script, &[opcodes::Ordinary::OP_CODESEPARATOR as u8]);
|
script_find_and_remove(&mut script, &[opcodes::Ordinary::OP_CODESEPARATOR as u8]);
|
||||||
|
@ -2447,12 +2447,12 @@ impl Default for Script {
|
||||||
|
|
||||||
impl_index_newtype!(Script, u8);
|
impl_index_newtype!(Script, u8);
|
||||||
|
|
||||||
impl ScriptBuilder {
|
impl Builder {
|
||||||
/// Creates a new empty script
|
/// Creates a new empty script
|
||||||
pub fn new() -> ScriptBuilder { ScriptBuilder(vec![]) }
|
pub fn new() -> Builder { Builder(vec![]) }
|
||||||
|
|
||||||
/// Creates a new script from an existing vector
|
/// Creates a new script from an existing vector
|
||||||
pub fn from_vec(v: Vec<u8>) -> ScriptBuilder { ScriptBuilder(v) }
|
pub fn from_vec(v: Vec<u8>) -> Builder { Builder(v) }
|
||||||
|
|
||||||
/// The length in bytes of the script
|
/// The length in bytes of the script
|
||||||
pub fn len(&self) -> usize { self.0.len() }
|
pub fn len(&self) -> usize { self.0.len() }
|
||||||
|
@ -2516,11 +2516,11 @@ impl ScriptBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds an individual opcode to the script
|
/// Adds an individual opcode to the script
|
||||||
impl Default for ScriptBuilder {
|
impl Default for Builder {
|
||||||
fn default() -> ScriptBuilder { ScriptBuilder(vec![]) }
|
fn default() -> Builder { Builder(vec![]) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_index_newtype!(ScriptBuilder, u8);
|
impl_index_newtype!(Builder, u8);
|
||||||
|
|
||||||
// User-facing serialization
|
// User-facing serialization
|
||||||
impl serde::Serialize for Script {
|
impl serde::Serialize for Script {
|
||||||
|
@ -2554,7 +2554,7 @@ impl<D: SimpleDecoder> ConsensusDecodable<D> for Script {
|
||||||
mod test {
|
mod test {
|
||||||
use serialize::hex::FromHex;
|
use serialize::hex::FromHex;
|
||||||
|
|
||||||
use super::{Error, Script, ScriptBuilder, build_scriptint, read_scriptint, read_scriptbool};
|
use super::{Error, Script, Builder, build_scriptint, read_scriptint, read_scriptbool};
|
||||||
use super::MaybeOwned::Owned;
|
use super::MaybeOwned::Owned;
|
||||||
|
|
||||||
use network::serialize::{deserialize, serialize};
|
use network::serialize::{deserialize, serialize};
|
||||||
|
@ -2585,7 +2585,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn script() {
|
fn script() {
|
||||||
let mut comp = vec![];
|
let mut comp = vec![];
|
||||||
let mut script = ScriptBuilder::new();
|
let mut script = Builder::new();
|
||||||
assert_eq!(&script[..], &comp[..]);
|
assert_eq!(&script[..], &comp[..]);
|
||||||
|
|
||||||
// small ints
|
// small ints
|
||||||
|
@ -2636,7 +2636,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn script_eval_simple() {
|
fn script_eval_simple() {
|
||||||
let mut script = ScriptBuilder::new();
|
let mut script = Builder::new();
|
||||||
assert!(script.clone().into_script().evaluate(&mut vec![], None, None).is_ok());
|
assert!(script.clone().into_script().evaluate(&mut vec![], None, None).is_ok());
|
||||||
|
|
||||||
script.push_opcode(opcodes::All::OP_RETURN);
|
script.push_opcode(opcodes::All::OP_RETURN);
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crypto::digest::Digest;
|
||||||
use crypto::sha2::Sha256;
|
use crypto::sha2::Sha256;
|
||||||
use std::ops;
|
use std::ops;
|
||||||
|
|
||||||
use blockdata::script::{Script, ScriptBuilder};
|
use blockdata::script;
|
||||||
use blockdata::opcodes;
|
use blockdata::opcodes;
|
||||||
use network::constants::Network;
|
use network::constants::Network;
|
||||||
use util::hash::Ripemd160Hash;
|
use util::hash::Ripemd160Hash;
|
||||||
|
@ -52,8 +52,8 @@ impl Address {
|
||||||
|
|
||||||
/// Generates a script pubkey spending to this address
|
/// Generates a script pubkey spending to this address
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn script_pubkey(&self) -> Script {
|
pub fn script_pubkey(&self) -> script::Script {
|
||||||
let mut script = ScriptBuilder::new();
|
let mut script = script::Builder::new();
|
||||||
script.push_opcode(opcodes::All::OP_DUP);
|
script.push_opcode(opcodes::All::OP_DUP);
|
||||||
script.push_opcode(opcodes::All::OP_HASH160);
|
script.push_opcode(opcodes::All::OP_HASH160);
|
||||||
script.push_slice(&self.hash[..]);
|
script.push_slice(&self.hash[..]);
|
||||||
|
|
Loading…
Reference in New Issue