OSDN Git Service

Merge pull request #375 from Bytom/dev
[bytom/bytom-spv.git] / protocol / bc / legacy / issuance.go
1 package legacy
2
3 import (
4         "github.com/bytom/crypto/sha3pool"
5         "github.com/bytom/protocol/bc"
6 )
7
8 type IssuanceInput struct {
9         // Commitment
10         Nonce  []byte
11         Amount uint64
12         // Note: as long as we require serflags=0x7, we don't need to
13         // explicitly store the asset ID here even though it's technically
14         // part of the input commitment. We can compute it instead from
15         // values in the witness (which, with serflags other than 0x7,
16         // might not be present).
17
18         // Witness
19         IssuanceWitness
20 }
21
22 func (ii *IssuanceInput) IsIssuance() bool { return true }
23 func (ii *IssuanceInput) IsCoinbase() bool { return false }
24
25 func (ii *IssuanceInput) AssetID() bc.AssetID {
26         defhash := ii.AssetDefinitionHash()
27         return bc.ComputeAssetID(ii.IssuanceProgram, &ii.InitialBlock, ii.VMVersion, &defhash)
28 }
29
30 func (ii *IssuanceInput) AssetDefinitionHash() (defhash bc.Hash) {
31         sha := sha3pool.Get256()
32         defer sha3pool.Put256(sha)
33         sha.Write(ii.AssetDefinition)
34         defhash.ReadFrom(sha)
35         return defhash
36 }
37
38 func NewIssuanceInput(
39         nonce []byte,
40         amount uint64,
41         referenceData []byte,
42         initialBlock bc.Hash,
43         issuanceProgram []byte,
44         arguments [][]byte,
45         assetDefinition []byte,
46 ) *TxInput {
47         return &TxInput{
48                 AssetVersion:  1,
49                 ReferenceData: referenceData,
50                 TypedInput: &IssuanceInput{
51                         Nonce:  nonce,
52                         Amount: amount,
53                         IssuanceWitness: IssuanceWitness{
54                                 InitialBlock:    initialBlock,
55                                 AssetDefinition: assetDefinition,
56                                 VMVersion:       1,
57                                 IssuanceProgram: issuanceProgram,
58                                 Arguments:       arguments,
59                         },
60                 },
61         }
62 }