OSDN Git Service

Merge pull request #519 from Bytom/dev
[bytom/bytom.git] / protocol / bc / types / issuance.go
1 package types
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.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         issuanceProgram []byte,
42         arguments [][]byte,
43         assetDefinition []byte,
44 ) *TxInput {
45         return &TxInput{
46                 AssetVersion:  1,
47                 TypedInput: &IssuanceInput{
48                         Nonce:  nonce,
49                         Amount: amount,
50                         IssuanceWitness: IssuanceWitness{
51                                 AssetDefinition: assetDefinition,
52                                 VMVersion:       1,
53                                 IssuanceProgram: issuanceProgram,
54                                 Arguments:       arguments,
55                         },
56                 },
57         }
58 }