7 log "github.com/sirupsen/logrus"
9 "github.com/bytom/vapor/blockchain/txbuilder"
10 "github.com/bytom/vapor/consensus"
11 "github.com/bytom/vapor/crypto/ed25519/chainkd"
12 "github.com/bytom/vapor/protocol/bc"
13 "github.com/bytom/vapor/protocol/bc/types"
16 func NewCrosschainTx(privateKey string) *types.Tx {
18 if err := xprv.UnmarshalText([]byte(privateKey)); err != nil {
19 log.WithField("err", err).Panic("fail on xprv UnmarshalText")
23 randomHash := [32]byte{}
24 rand.Seed(time.Now().UnixNano())
25 rand.Read(randomHash[:])
26 builder := txbuilder.NewBuilder(time.Now())
27 input := types.NewCrossChainInput(nil, bc.NewHash(randomHash), *consensus.BTMAssetID, 10000000, 1, 1, []byte{}, []byte{})
28 if err := builder.AddInput(input, &txbuilder.SigningInstruction{}); err != nil {
29 log.WithField("err", err).Panic("fail on add builder input")
32 output := types.NewIntraChainOutput(*consensus.BTMAssetID, 10000000, []byte{0x00, 0x14, 0xd4, 0x88, 0xda, 0x3b, 0x78, 0x1a, 0xa4, 0xe1, 0xdb, 0x9b, 0x7b, 0x27, 0x4d, 0xf1, 0x04, 0x33, 0x54, 0x83, 0x0b, 0x07})
33 if err := builder.AddOutput(output); err != nil {
34 log.WithField("err", err).Panic("fail on add builder output")
37 tpl, _, err := builder.Build()
39 log.WithField("err", err).Panic("fail on add builder tx")
43 signHash := tpl.Hash(0).Byte32()
44 sign := xprv.Sign(signHash[:])
45 tpl.Transaction.SetInputArguments(0, [][]byte{sign})
47 data, err := tpl.Transaction.TxData.MarshalText()
49 log.WithField("err", err).Panic("fail on unmarshal tx")
52 tpl.Transaction.TxData.SerializedSize = uint64(len(data) / 2)
53 tpl.Transaction.Tx.SerializedSize = uint64(len(data) / 2)
54 return tpl.Transaction