Skip to content

Commit

Permalink
feat(transaction): add marshal method for script group
Browse files Browse the repository at this point in the history
Signed-off-by: Minh Huy Tran <[email protected]>
  • Loading branch information
NhoxxKienn authored and ravi0131 committed Oct 16, 2024
1 parent e184b64 commit d1c9686
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
24 changes: 24 additions & 0 deletions transaction/script_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transaction

import (
"encoding/json"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/nervosnetwork/ckb-sdk-go/v2/types"
)
Expand Down Expand Up @@ -43,3 +44,26 @@ func (r *ScriptGroup) UnmarshalJSON(input []byte) error {
}
return nil
}

func (r *ScriptGroup) MarshalJSON() ([]byte, error) {
toHexutilArray := func(in []uint32) []hexutil.Uint {
out := make([]hexutil.Uint, len(in))
for i, data := range in {
out[i] = hexutil.Uint(data)
}
return out
}

jsonObj := struct {
Script *types.Script `json:"script"`
GroupType types.ScriptType `json:"group_type"`
InputIndices []hexutil.Uint `json:"input_indices"`
OutputIndices []hexutil.Uint `json:"output_indices"`
}{
Script: r.Script,
GroupType: r.GroupType,
InputIndices: toHexutilArray(r.InputIndices),
OutputIndices: toHexutilArray(r.OutputIndices),
}
return json.Marshal(jsonObj)
}
7 changes: 4 additions & 3 deletions transaction/signer_test/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"runtime/debug"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/nervosnetwork/ckb-sdk-go/v2/crypto/secp256k1"
Expand All @@ -13,9 +17,6 @@ import (
"github.com/nervosnetwork/ckb-sdk-go/v2/transaction/signer/omnilock"
"github.com/nervosnetwork/ckb-sdk-go/v2/types"
"github.com/stretchr/testify/assert"
"os"
"runtime/debug"
"testing"
)

func TestIsSingleSigMatched(t *testing.T) {
Expand Down

0 comments on commit d1c9686

Please sign in to comment.