Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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