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