OSDN Git Service

e171fe146b2c761f50d74f2601e0a68c606e2912
[bytom/vapor.git] / protocol / bc / types / issuance.go
1 package types
2
3 import (
4         "github.com/vapor/crypto/sha3pool"
5         "github.com/vapor/protocol/bc"
6 )
7
8 // IssuanceInput satisfies the TypedInput interface and represents a issuance.
9 type IssuanceInput struct {
10         Nonce  []byte
11         Amount uint64
12
13         AssetDefinition []byte
14         VMVersion       uint64
15         IssuanceProgram []byte
16         Arguments       [][]byte
17 }
18
19 // NewIssuanceInput create a new IssuanceInput struct.
20 func NewIssuanceInput(nonce []byte, amount uint64, issuanceProgram []byte, arguments [][]byte, assetDefinition []byte) *TxInput {
21         return &TxInput{
22                 AssetVersion: 1,
23                 TypedInput: &IssuanceInput{
24                         Nonce:           nonce,
25                         Amount:          amount,
26                         AssetDefinition: assetDefinition,
27                         VMVersion:       1,
28                         IssuanceProgram: issuanceProgram,
29                         Arguments:       arguments,
30                 },
31         }
32 }
33
34 // InputType is the interface function for return the input type.
35 func (ii *IssuanceInput) InputType() uint8 { return IssuanceInputType }
36
37 // AssetID calculate the assetID of the issuance input.
38 func (ii *IssuanceInput) AssetID() bc.AssetID {
39         defhash := ii.AssetDefinitionHash()
40         return bc.ComputeAssetID(ii.IssuanceProgram, ii.VMVersion, &defhash)
41 }
42
43 // AssetDefinitionHash return the hash of the issuance asset definition.
44 func (ii *IssuanceInput) AssetDefinitionHash() (defhash bc.Hash) {
45         sha := sha3pool.Get256()
46         defer sha3pool.Put256(sha)
47         sha.Write(ii.AssetDefinition)
48         defhash.ReadFrom(sha)
49         return defhash
50 }
51
52 // NonceHash return the hash of the issuance asset definition.
53 func (ii *IssuanceInput) NonceHash() (hash bc.Hash) {
54         sha := sha3pool.Get256()
55         defer sha3pool.Put256(sha)
56         sha.Write(ii.Nonce)
57         hash.ReadFrom(sha)
58         return hash
59 }