xuperchain/xuper-sdk-go

sdk在无币模式下,部署和调用合约会触发空指针异常

Closed this issue · 0 comments

sdk在无币模式下,部署和调用合约会触发空指针异常

// GenerateTxInput generate txinput part
func (xc *Xchain) GenerateTxInput(utxoOutputs *pb.UtxoOutput, totalNeed *big.Int) (
	[]*pb.TxInput, *pb.TxOutput, error) {
	// utxoList => TxInput
	//
	// gen txInputs
	var txInputs []*pb.TxInput
	var txOutput *pb.TxOutput

        //utxoOutputs是空对象
	for _, utxo := range utxoOutputs.UtxoList {
		txInput := &pb.TxInput{}
		txInput.RefTxid = utxo.RefTxid
		txInput.RefOffset = utxo.RefOffset
		txInput.FromAddr = utxo.ToAddr
		txInput.Amount = utxo.Amount
		txInputs = append(txInputs, txInput)
	}
}

错误描述

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x90c047]

goroutine 6 [running]:
testing.tRunner.func1(0xc0000f2300)
	/usr/local/go/src/testing/testing.go:874 +0x3a3
panic(0x9ad1e0, 0xf36b90)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenerateTxInput(0xc0002a6420, 0x0, 0xc000303b60, 0x0, 0x1, 0x40db86, 0x12, 0x0, 0xc0002ca310)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/xchain/xchain.go:208 +0x37
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenComplianceCheckTx(0xc0002a6420, 0xc0000a2870, 0x20, 0xc0002aee00, 0x3a)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/xchain/xchain.go:99 +0xa1
github.com/xuperchain/xuper-sdk-go/xchain.(*Xchain).GenCompleteTxAndPost(0xc0002a6420, 0xc0000a2870, 0xa81602, 0x1, 0x2, 0xc0002aee00)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/xchain/xchain.go:407 +0x4d
github.com/xuperchain/xuper-sdk-go/contract.(*WasmContract).PostWasmContract(0xc0002a6410, 0xc0000a2870, 0xa821d8, 0x25, 0xa6a20d, 0x1)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/contract/contract.go:100 +0x141
github.com/xuperchain/xuper-sdk-go/contract.(*WasmContract).DeployWasmContract(0xc0002a6410, 0xc0000e3e20, 0xa821d8, 0x25, 0xa6a20d, 0x1, 0x8, 0xa78ad3, 0x18, 0xc0002a6410)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/contract/contract.go:52 +0x126
github.com/xuperchain/xuper-sdk-go/contract.TestJason(0xc0000f2300)
	/home/jason/桌面/github.com/xuperchain/xuper-sdk-go/contract/contract_test.go:216 +0x2fb
testing.tRunner(0xc0000f2300, 0xa9c368)
	/usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:960 +0x350