Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shaojunda
Last active December 31, 2020 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaojunda/464fd7e8d916e683743ec53dcce69788 to your computer and use it in GitHub Desktop.
Save shaojunda/464fd7e8d916e683743ec53dcce69788 to your computer and use it in GitHub Desktop.
claim cheque cell example
func processBlockData(client rpc.Client, systemScripts *utils.SystemScripts, blockNumber uint64) error {
block, err := client.GetBlockByNumber(context.Background(), blockNumber)
if err != nil {
return err
}
for _, tx := range block.Transactions {
for _, output := range tx.Outputs {
addr, err := address.Generate(address.Mainnet, output.Lock)
if err != nil {
return err
}
if !isExchangeManagedAddress(addr) {
continue
}
if utils.IsChequeCell(output, systemScripts) && output.Type != nil {
// find addr's sk
sk := "addr's PRIVATE KEY"
key, err := s.HexToKey(sk)
txHash, err := claimChequeCell(addr, output, client, systemScripts, key)
if err != nil {
return err
}
log.Println(txHash)
}
}
}
return nil
}
func isExchangeManagedAddress(addr string) bool {
return true
}
func claimChequeCell(addr string, output *types.CellOutput, client rpc.Client, systemScripts *utils.SystemScripts, key crypto.Key) (string, error){
// claim cheque cell
uuid := hex.EncodeToString(output.Type.Args)
c, err := payment.NewClaimCheque(addr, uuid, 1000, systemScripts)
if err != nil {
return "", err
}
_, err = c.GenerateClaimChequeUnsignedTx(client, systemScripts)
if err != nil {
return "", err
}
_, err = c.SignTx(key)
if err != nil {
return "", err
}
txHash, err := c.Send(client)
if err != nil {
return "", err
}
return txHash.String(), err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment