Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Nonce attribute of IssueAsset Transaction #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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