Skip to content

Commit

Permalink
add Nonce attribute of IssueAsset Transaction.
Browse files Browse the repository at this point in the history
Signed-off-by: zhengq1 <[email protected]>
  • Loading branch information
zhengq1 committed Aug 9, 2017
1 parent 45e843a commit 8dd808b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/transaction/TransactionBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions core/transaction/payload/IssueAsset.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions net/httpjsonrpc/TransPayloadToHex.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type DeployCodeInfo struct {

//implement PayloadInfo define IssueAssetInfo
type IssueAssetInfo struct {
Nonce uint64
}

type IssuerInfo struct {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8dd808b

Please sign in to comment.