(n int64)
| 53 | } |
| 54 | |
| 55 | func ScriptNumSerialize(n int64) []byte { |
| 56 | if n == 0 { |
| 57 | return []byte{} |
| 58 | } |
| 59 | var res []byte |
| 60 | neg := false |
| 61 | if n < 0 { |
| 62 | neg = true |
| 63 | n = -n |
| 64 | } |
| 65 | |
| 66 | for n > 0 { |
| 67 | res = append(res, byte(n&0xff)) |
| 68 | n >>= 8 |
| 69 | } |
| 70 | |
| 71 | if res[len(res)-1]&0x80 != 0 { |
| 72 | if neg { |
| 73 | res = append(res, 0x80) |
| 74 | } else { |
| 75 | res = append(res, 0) |
| 76 | } |
| 77 | } else if neg { |
| 78 | res[len(res)-1] |= 0x80 |
| 79 | } |
| 80 | |
| 81 | return res |
| 82 | } |
| 83 | |
| 84 | func appendData(res, w []byte) []byte { |
| 85 | if len(w) < opcodes.OP_PUSHDATA1 { |