Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
add sig for nft contract func
Browse files Browse the repository at this point in the history
  • Loading branch information
boomyl committed Oct 20, 2021
1 parent b954590 commit c3610f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 21 additions & 1 deletion nft/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,20 @@ func NewContract(platformScript []byte, marginFold uint64) ([]byte, error) {

builder.SetJumpTarget(0)
// alt stack [creater, taxRate, nftAsset, owner, marginAsset, marginAmount]
// data statck [newMarginAmount]
// data statck [ownerSig, newMarginAmount]
swapAltStack(builder, 0, 0)
// alt stack [creater, taxRate, nftAsset, owner, newMarginAsset, newMarginAmount]
// data statck [ownerSig]
cpAltStack(builder, 2)
// alt stack [creater, taxRate, nftAsset, owner, newMarginAsset, newMarginAmount]
// data statck [ownerSig, owner]
builder.AddOp(vm.OP_TXSIGHASH)
builder.AddOp(vm.OP_SWAP)
// alt stack [creater, taxRate, nftAsset, owner, newMarginAsset, newMarginAmount]
// data statck [ownerSig, txSigHash, owner]
builder.AddOp(vm.OP_CHECKSIG)
builder.AddOp(vm.OP_VERIFY)
// alt stack [creater, taxRate, nftAsset, owner, newMarginAsset, newMarginAmount]
// data statck []
builder.SetJumpTarget(1)
builder.AddUint64(0)
Expand Down Expand Up @@ -119,6 +130,14 @@ func NewOffer(nftContract []byte) ([]byte, error) {
builder.AddJumpIf(0)
builder.AddUint64(1)
builder.AddJump(1)

// need check sig for cancel func
cpAltStack(builder, 2)
builder.AddOp(vm.OP_TXSIGHASH)
builder.AddOp(vm.OP_SWAP)
builder.AddOp(vm.OP_CHECKSIG)
builder.AddOp(vm.OP_VERIFY)

builder.SetJumpTarget(0)
builder.AddUint64(0)
builder.AddUint64(1)
Expand All @@ -134,6 +153,7 @@ func NewOffer(nftContract []byte) ([]byte, error) {
builder.AddData(nftContract)
builder.AddOp(vm.OP_CHECKOUTPUT)
builder.SetJumpTarget(1)

return builder.Build()
}

Expand Down
6 changes: 4 additions & 2 deletions nft/nft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var (
ETH = testutil.MustDecodeAsset("78de44ffa1bce37b757c9eae8925b5f199dc4621b412ef0f3f46168865284a93")

utxoSourceID = testutil.MustDecodeHash("762ec536ea64f71feac5fd4000a4807fc8e9d08d757889bd0206a02b79f9db8e")
ownerScirpt = []byte("ownerScirpt")
buyerScirpt = []byte("buyerScirpt")
ownerScirpt = testutil.MustDecodeHexString("0100000000000000000000000000000000000000000000000000000000000000") //[]byte("ownerScirpt")
buyerScirpt = testutil.MustDecodeHexString("0100000000000000000000000000000000000000000000000000000000000000") //[]byte("buyerScirpt")
)

// 从2个BTC的押金换成3个BTC的
Expand Down Expand Up @@ -52,6 +52,7 @@ func TestEditMargin(t *testing.T) {
}

arguments := [][]byte{
testutil.MustDecodeHexString("6c25b3220df660b06bf17ca881e6a31811fc4f33f78e5c0597a1e29b5d0030d9494bff417a237b907eac5cdce1dc0dfe1f258103dee32fcc84a2dd5e8c614209"),
vm.Uint64Bytes(300000000),
vm.Uint64Bytes(1),
}
Expand Down Expand Up @@ -272,6 +273,7 @@ func TestCancelOffer(t *testing.T) {
}

arguments := [][]byte{
testutil.MustDecodeHexString("2dbbae17e2aed7639ba212f46fd28b9ccb122c1a24ebd1a48e2dddcaf675252e9adb7c8fe504fa4aad4d054d87701d93d67c5e62bee9ccdc442a39a207dcd106"),
vm.Uint64Bytes(0),
}

Expand Down

0 comments on commit c3610f1

Please sign in to comment.