OSDN Git Service

15db5dc4caa6b02560a02da7f0d19a13198082ce
[bytom/bytom-java-sdk.git] / tx-signer / src / main / java / io / bytom / offline / api / Output.java
1 package io.bytom.offline.api;
2
3 import io.bytom.offline.common.Utils;
4 import org.bouncycastle.util.encoders.Hex;
5 import java.io.ByteArrayOutputStream;
6 import java.io.IOException;
7
8 public class Output {
9
10     /**
11      * The number of units of the asset being controlled.
12      */
13     private Long amount;
14
15     /**
16      * The id of the asset being controlled.
17      */
18     private String assetId;
19
20     /**
21      * The control program which must be satisfied to transfer this output.
22      */
23     private String controlProgram;
24
25     /**
26      * The id of the output.
27      */
28     private String id;
29
30     /**
31      * The output's position in a transaction's list of outputs.
32      */
33     private Integer position;
34
35     public Output(String assetId, Long amount, String controlProgram) {
36         this.assetId = assetId;
37         this.amount = amount;
38         this.controlProgram = controlProgram;
39     }
40
41     public byte[] serializeOutput() throws IOException {
42         ByteArrayOutputStream stream = new ByteArrayOutputStream();
43
44         //assetVersion
45         Utils.writeVarint(1, stream); //AssetVersion是否默认为1
46         //outputCommit
47         ByteArrayOutputStream outputCommitSteam = new ByteArrayOutputStream();
48         //assetId
49         outputCommitSteam.write(Hex.decode(assetId));
50         //amount
51         Utils.writeVarint(amount, outputCommitSteam);
52         //vmVersion
53         Utils.writeVarint(1, outputCommitSteam); //db中获取vm_version
54         //controlProgram
55         Utils.writeVarStr(Hex.decode(controlProgram), outputCommitSteam);
56
57         Utils.writeExtensibleString(outputCommitSteam.toByteArray(), stream);
58
59         //outputWitness
60         Utils.writeVarint(0, stream);
61         return stream.toByteArray();
62     }
63
64     public Long getAmount() {
65         return amount;
66     }
67
68     public void setAmount(Long amount) {
69         this.amount = amount;
70     }
71
72     public String getAssetId() {
73         return assetId;
74     }
75
76     public void setAssetId(String assetId) {
77         this.assetId = assetId;
78     }
79
80     public String getControlProgram() {
81         return controlProgram;
82     }
83
84     public void setControlProgram(String controlProgram) {
85         this.controlProgram = controlProgram;
86     }
87
88     public String getId() {
89         return id;
90     }
91
92     public void setId(String id) {
93         this.id = id;
94     }
95
96     public Integer getPosition() {
97         return position;
98     }
99
100     public void setPosition(Integer position) {
101         this.position = position;
102     }
103 }