diff --git a/core/transaction/TransactionBuilder.go b/core/transaction/TransactionBuilder.go index 63fb2829..c67ca9a8 100644 --- a/core/transaction/TransactionBuilder.go +++ b/core/transaction/TransactionBuilder.go @@ -6,6 +6,8 @@ import ( "DNA/core/contract/program" "DNA/core/transaction/payload" "DNA/crypto" + "math/rand" + "time" ) //initial a new transaction with asset registration payload @@ -57,7 +59,10 @@ func NewBookKeeperTransaction(pubKey *crypto.PubKey, isAdd bool, cert []byte) (* func NewIssueAssetTransaction(outputs []*TxOutput) (*Transaction, error) { - assetRegPayload := &payload.IssueAsset{} + r := rand.New(rand.NewSource(time.Now().UnixNano())) + assetRegPayload := &payload.IssueAsset{ + Nonce: r.Uint64(), + } return &Transaction{ TxType: IssueAsset, diff --git a/core/transaction/payload/IssueAsset.go b/core/transaction/payload/IssueAsset.go index 2339dbb3..9b0935fa 100644 --- a/core/transaction/payload/IssueAsset.go +++ b/core/transaction/payload/IssueAsset.go @@ -1,10 +1,14 @@ package payload -import "io" +import ( + "DNA/common/serialization" + "io" +) const IssueAssetPayloadVersion byte = 0x00 type IssueAsset struct { + Nonce uint64 } func (a *IssueAsset) Data(version byte) []byte { @@ -14,9 +18,11 @@ func (a *IssueAsset) Data(version byte) []byte { } func (a *IssueAsset) Serialize(w io.Writer, version byte) error { - return nil + return serialization.WriteUint64(w, a.Nonce) } func (a *IssueAsset) Deserialize(r io.Reader, version byte) error { - return nil + var err error + a.Nonce, err = serialization.ReadUint64(r) + return err } diff --git a/net/httpjsonrpc/TransPayloadToHex.go b/net/httpjsonrpc/TransPayloadToHex.go index c03bbe21..6b541599 100644 --- a/net/httpjsonrpc/TransPayloadToHex.go +++ b/net/httpjsonrpc/TransPayloadToHex.go @@ -34,6 +34,7 @@ type DeployCodeInfo struct { //implement PayloadInfo define IssueAssetInfo type IssueAssetInfo struct { + Nonce uint64 } type IssuerInfo struct { @@ -95,6 +96,9 @@ func TransPayloadToHex(p Payload) PayloadInfo { } return obj case *payload.IssueAsset: + obj := new(IssueAssetInfo) + obj.Nonce = object.Nonce + return obj case *payload.TransferAsset: case *payload.DeployCode: obj := new(DeployCodeInfo)