Commit 50c8a8ae authored by 袁兴强's avatar 袁兴强

update

parent 9039974b
package wasm package wasm
import ( import (
sdk "github.com/33cn/chain33-sdk-go"
"github.com/33cn/chain33-sdk-go/crypto"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"time"
sdk "github.com/33cn/chain33-sdk-go"
"github.com/33cn/chain33-sdk-go/crypto"
"github.com/33cn/chain33-sdk-go/types" "github.com/33cn/chain33-sdk-go/types"
) )
var r *rand.Rand
func init() {
r = rand.New(rand.NewSource(time.Now().UnixNano()))
}
func CreateWasmCreateTx(paraName, path, name string, privKey, cert, uid []byte) (*types.Transaction, error) { func CreateWasmCreateTx(paraName, path, name string, privKey, cert, uid []byte) (*types.Transaction, error) {
code, err := ioutil.ReadFile(path) code, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
...@@ -23,7 +30,7 @@ func CreateWasmCreateTx(paraName, path, name string, privKey, cert, uid []byte) ...@@ -23,7 +30,7 @@ func CreateWasmCreateTx(paraName, path, name string, privKey, cert, uid []byte)
}, },
}, },
} }
tx := &types.Transaction{Execer: []byte(paraName + WasmX), Payload: types.Encode(payload), Fee: 1e5, Nonce: rand.Int63()} tx := &types.Transaction{Execer: []byte(paraName + WasmX), Payload: types.Encode(payload), Fee: 1e5, Nonce: r.Int63(), To: crypto.GetExecAddress(paraName + WasmX)}
tx, err = sdk.Sign(tx, privKey, crypto.SM2, uid) tx, err = sdk.Sign(tx, privKey, crypto.SM2, uid)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -44,7 +51,7 @@ func CreateWasmCallTx(paraName, contract, method string, param []int64, env []st ...@@ -44,7 +51,7 @@ func CreateWasmCallTx(paraName, contract, method string, param []int64, env []st
}, },
}, },
} }
tx := &types.Transaction{Execer: []byte(paraName + WasmX), Payload: types.Encode(payload), Fee: 1e5, Nonce: rand.Int63()} tx := &types.Transaction{Execer: []byte(paraName + WasmX), Payload: types.Encode(payload), Fee: 1e5, Nonce: r.Int63(), To: crypto.GetExecAddress(paraName + WasmX)}
var err error var err error
tx, err = sdk.Sign(tx, privKey, crypto.SM2, uid) tx, err = sdk.Sign(tx, privKey, crypto.SM2, uid)
if err != nil { if err != nil {
...@@ -52,4 +59,4 @@ func CreateWasmCallTx(paraName, contract, method string, param []int64, env []st ...@@ -52,4 +59,4 @@ func CreateWasmCallTx(paraName, contract, method string, param []int64, env []st
} }
tx.Signature.Signature = crypto.EncodeCertToSignature(tx.Signature.Signature, cert, uid) tx.Signature.Signature = crypto.EncodeCertToSignature(tx.Signature.Signature, cert, uid)
return tx, nil return tx, nil
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment