| 90 | } |
| 91 | |
| 92 | func (t *TxInput) readFrom(r *blockchain.Reader) (err error) { |
| 93 | t.AssetVersion, err = blockchain.ReadVarint63(r) |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | var ( |
| 99 | ii *IssuanceInput |
| 100 | si *SpendInput |
| 101 | assetID bc.AssetID |
| 102 | ) |
| 103 | |
| 104 | t.CommitmentSuffix, err = blockchain.ReadExtensibleString(r, func(r *blockchain.Reader) error { |
| 105 | if t.AssetVersion != 1 { |
| 106 | return nil |
| 107 | } |
| 108 | var icType [1]byte |
| 109 | _, err = io.ReadFull(r, icType[:]) |
| 110 | if err != nil { |
| 111 | return errors.Wrap(err, "reading input commitment type") |
| 112 | } |
| 113 | switch icType[0] { |
| 114 | case 0: |
| 115 | ii = new(IssuanceInput) |
| 116 | |
| 117 | ii.Nonce, err = blockchain.ReadVarstr31(r) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | _, err = assetID.ReadFrom(r) |
| 122 | if err != nil { |
| 123 | return err |
| 124 | } |
| 125 | ii.Amount, err = blockchain.ReadVarint63(r) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | case 1: |
| 131 | si = new(SpendInput) |
| 132 | si.SpendCommitmentSuffix, err = si.SpendCommitment.readFrom(r, 1) |
| 133 | if err != nil { |
| 134 | return err |
| 135 | } |
| 136 | |
| 137 | default: |
| 138 | return fmt.Errorf("unsupported input type %d", icType[0]) |
| 139 | } |
| 140 | return nil |
| 141 | }) |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | |
| 146 | t.ReferenceData, err = blockchain.ReadVarstr31(r) |
| 147 | if err != nil { |
| 148 | return err |
| 149 | } |