Skip to content

Commit

Permalink
feat: support custom SystemScripts
Browse files Browse the repository at this point in the history
BREAKING CHANGE: need send a SystemScripts to `GenerateTx` method manually
  • Loading branch information
shaojunda committed Dec 9, 2020
1 parent 9ad024b commit f851553
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions payment/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func NewPayment(from, to string, amount, fee uint64) (*Payment, error) {
}, nil
}

func (p *Payment) GenerateTx(client rpc.Client) (*types.Transaction, error) {
return generateTxWithIndexer(client, p)
func (p *Payment) GenerateTx(client rpc.Client, systemScripts *utils.SystemScripts) (*types.Transaction, error) {
return generateTxWithIndexer(client, p, systemScripts)
}

func generateTxWithIndexer(client rpc.Client, p *Payment) (*types.Transaction, error) {
func generateTxWithIndexer(client rpc.Client, p *Payment, systemScripts *utils.SystemScripts) (*types.Transaction, error) {
searchKey := &indexer.SearchKey{
Script: p.From,
ScriptType: indexer.ScriptTypeLock,
Expand All @@ -64,11 +64,6 @@ func generateTxWithIndexer(client rpc.Client, p *Payment) (*types.Transaction, e
return nil, fmt.Errorf("insufficient balance: %d", result.Capacity)
}

systemScripts, err := utils.NewSystemScripts(client)
if err != nil {
return nil, fmt.Errorf("load system script error: %v", err)
}

tx := transaction.NewSecp256k1SingleSigTx(systemScripts)
tx.Outputs = append(tx.Outputs, &types.CellOutput{
Capacity: p.Amount,
Expand Down

0 comments on commit f851553

Please sign in to comment.