Comment ScriptInfo struct according to standards.

Found by golint.
This commit is contained in:
Dave Collins 2014-10-12 19:39:01 -05:00
parent c0c3d860d6
commit ce0a334329

View file

@ -635,67 +635,67 @@ func (s *Script) CheckErrorCondition() (err error) {
// will return true in the case that the last opcode was successfully executed. // will return true in the case that the last opcode was successfully executed.
// if an error is returned then the result of calling Step or any other method // if an error is returned then the result of calling Step or any other method
// is undefined. // is undefined.
func (m *Script) Step() (done bool, err error) { func (s *Script) Step() (done bool, err error) {
// verify that it is pointing to a valid script address // verify that it is pointing to a valid script address
err = m.validPC() err = s.validPC()
if err != nil { if err != nil {
return true, err return true, err
} }
opcode := m.scripts[m.scriptidx][m.scriptoff] opcode := s.scripts[s.scriptidx][s.scriptoff]
err = opcode.exec(m) err = opcode.exec(s)
if err != nil { if err != nil {
return true, err return true, err
} }
if m.dstack.Depth()+m.astack.Depth() > maxStackSize { if s.dstack.Depth()+s.astack.Depth() > maxStackSize {
return false, ErrStackOverflow return false, ErrStackOverflow
} }
// prepare for next instruction // prepare for next instruction
m.scriptoff++ s.scriptoff++
if m.scriptoff >= len(m.scripts[m.scriptidx]) { if s.scriptoff >= len(s.scripts[s.scriptidx]) {
// Illegal to have an `if' that straddles two scripts. // Illegal to have an `if' that straddles two scripts.
if err == nil && len(m.condStack) != 1 { if err == nil && len(s.condStack) != 1 {
return false, ErrStackMissingEndif return false, ErrStackMissingEndif
} }
// alt stack doesn't persist. // alt stack doesn't persist.
_ = m.astack.DropN(m.astack.Depth()) _ = s.astack.DropN(s.astack.Depth())
m.numOps = 0 // number of ops is per script. s.numOps = 0 // number of ops is per script.
m.scriptoff = 0 s.scriptoff = 0
if m.scriptidx == 0 && m.bip16 { if s.scriptidx == 0 && s.bip16 {
m.scriptidx++ s.scriptidx++
m.savedFirstStack = m.GetStack() s.savedFirstStack = s.GetStack()
} else if m.scriptidx == 1 && m.bip16 { } else if s.scriptidx == 1 && s.bip16 {
// Put us past the end for CheckErrorCondition() // Put us past the end for CheckErrorCondition()
m.scriptidx++ s.scriptidx++
// We check script ran ok, if so then we pull // We check script ran ok, if so then we pull
// the script out of the first stack and executre that. // the script out of the first stack and executre that.
err := m.CheckErrorCondition() err := s.CheckErrorCondition()
if err != nil { if err != nil {
return false, err return false, err
} }
script := m.savedFirstStack[len(m.savedFirstStack)-1] script := s.savedFirstStack[len(s.savedFirstStack)-1]
pops, err := parseScript(script) pops, err := parseScript(script)
if err != nil { if err != nil {
return false, err return false, err
} }
m.scripts = append(m.scripts, pops) s.scripts = append(s.scripts, pops)
// Set stack to be the stack from first script // Set stack to be the stack from first script
// minus the script itself // minus the script itself
m.SetStack(m.savedFirstStack[:len(m.savedFirstStack)-1]) s.SetStack(s.savedFirstStack[:len(s.savedFirstStack)-1])
} else { } else {
m.scriptidx++ s.scriptidx++
} }
// there are zero length scripts in the wild // there are zero length scripts in the wild
if m.scriptidx < len(m.scripts) && m.scriptoff >= len(m.scripts[m.scriptidx]) { if s.scriptidx < len(s.scripts) && s.scriptoff >= len(s.scripts[s.scriptidx]) {
m.scriptidx++ s.scriptidx++
} }
m.lastcodesep = 0 s.lastcodesep = 0
if m.scriptidx >= len(m.scripts) { if s.scriptidx >= len(s.scripts) {
return true, nil return true, nil
} }
} }
@ -704,55 +704,55 @@ func (m *Script) Step() (done bool, err error) {
// curPC returns either the current script and offset, or an error if the // curPC returns either the current script and offset, or an error if the
// position isn't valid. // position isn't valid.
func (m *Script) curPC() (script int, off int, err error) { func (s *Script) curPC() (script int, off int, err error) {
err = m.validPC() err = s.validPC()
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err
} }
return m.scriptidx, m.scriptoff, nil return s.scriptidx, s.scriptoff, nil
} }
// validPC returns an error if the current script position is valid for // validPC returns an error if the current script position is valid for
// execution, nil otherwise. // execution, nil otherwise.
func (m *Script) validPC() error { func (s *Script) validPC() error {
if m.scriptidx >= len(m.scripts) { if s.scriptidx >= len(s.scripts) {
return fmt.Errorf("Past input scripts %v:%v %v:xxxx", m.scriptidx, m.scriptoff, len(m.scripts)) return fmt.Errorf("Past input scripts %v:%v %v:xxxx", s.scriptidx, s.scriptoff, len(s.scripts))
} }
if m.scriptoff >= len(m.scripts[m.scriptidx]) { if s.scriptoff >= len(s.scripts[s.scriptidx]) {
return fmt.Errorf("Past input scripts %v:%v %v:%04d", m.scriptidx, m.scriptoff, m.scriptidx, len(m.scripts[m.scriptidx])) return fmt.Errorf("Past input scripts %v:%v %v:%04d", s.scriptidx, s.scriptoff, s.scriptidx, len(s.scripts[s.scriptidx]))
} }
return nil return nil
} }
// DisasmScript returns the disassembly string for the script at offset // DisasmScript returns the disassembly string for the script at offset
// ``idx''. Where 0 is the scriptSig and 1 is the scriptPubKey. // ``idx''. Where 0 is the scriptSig and 1 is the scriptPubKey.
func (m *Script) DisasmScript(idx int) (disstr string, err error) { func (s *Script) DisasmScript(idx int) (disstr string, err error) {
if idx >= len(m.scripts) { if idx >= len(s.scripts) {
return "", ErrStackInvalidIndex return "", ErrStackInvalidIndex
} }
for i := range m.scripts[idx] { for i := range s.scripts[idx] {
disstr = disstr + m.disasm(idx, i) + "\n" disstr = disstr + s.disasm(idx, i) + "\n"
} }
return disstr, nil return disstr, nil
} }
// DisasmPC returns the string for the disassembly of the opcode that will be // DisasmPC returns the string for the disassembly of the opcode that will be
// next to execute when Step() is called. // next to execute when Step() is called.
func (m *Script) DisasmPC() (disstr string, err error) { func (s *Script) DisasmPC() (disstr string, err error) {
scriptidx, scriptoff, err := m.curPC() scriptidx, scriptoff, err := s.curPC()
if err != nil { if err != nil {
return "", err return "", err
} }
return m.disasm(scriptidx, scriptoff), nil return s.disasm(scriptidx, scriptoff), nil
} }
// disasm is a helper member to produce the output for DisasmPC and // disasm is a helper member to produce the output for DisasmPC and
// DisasmScript. It produces the opcode prefixed by the program counter at the // DisasmScript. It produces the opcode prefixed by the program counter at the
// provided position in the script. it does no error checking and leaves that // provided position in the script. it does no error checking and leaves that
// to the caller to provide a valid offse. // to the caller to provide a valid offse.
func (m *Script) disasm(scriptidx int, scriptoff int) string { func (s *Script) disasm(scriptidx int, scriptoff int) string {
return fmt.Sprintf("%02x:%04x: %s", scriptidx, scriptoff, return fmt.Sprintf("%02x:%04x: %s", scriptidx, scriptoff,
m.scripts[scriptidx][scriptoff].print(false)) s.scripts[scriptidx][scriptoff].print(false))
} }
// subScript will return the script since the last OP_CODESEPARATOR // subScript will return the script since the last OP_CODESEPARATOR
@ -1526,16 +1526,21 @@ func expectedInputs(pops []parsedOpcode, class ScriptClass) int {
} }
} }
// ScriptInfo houses information about a script pair that is determined by
// CalcScriptInfo.
type ScriptInfo struct { type ScriptInfo struct {
// The class of the sigscript, equivalent to calling GetScriptClass // The class of the sigscript, equivalent to calling GetScriptClass
// on the sigScript. // on the sigScript.
PkScriptClass ScriptClass PkScriptClass ScriptClass
// the number of inputs provided by the pkScript
// NumInputs is the number of inputs provided by the pkScript.
NumInputs int NumInputs int
// the number of outputs required by sigScript and any
// ExpectedInputs is the number of outputs required by sigScript and any
// pay-to-script-hash scripts. The number will be -1 if unknown. // pay-to-script-hash scripts. The number will be -1 if unknown.
ExpectedInputs int ExpectedInputs int
// The nubmer of signature operations in the scriptpair.
// SigOps is the nubmer of signature operations in the script pair.
SigOps int SigOps int
} }