-
-
Save shaojunda/464fd7e8d916e683743ec53dcce69788 to your computer and use it in GitHub Desktop.
claim cheque cell example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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