英文:
Retrieve user's current delegation and rewards in Flow programmatically using user_id
问题
我想知道如何通过程序化方式在流程中传递用户 ID 来获取特定用户的当前委托和奖励!?我已尝试过 JavaScript SDK。但我猜它没有针对质押和奖励余额的支持
我需要关于此的帮助
英文:
I am wondering how can I get the current delegation and rewards of a particular user by passing its user_id programatically in flow (mostly in typescript or python) !? I have tried it js SDK. but their isnt any support in it for staking and reward balance i guess
I need help regarding this
答案1
得分: 2
import LockedTokens from 0x8d0e87b65159ae63
import FlowIDTableStaking from 0x8624b52f9ddcd04a
pub fun main(address:Address) : FlowIDTableStaking.DelegatorInfo {
let acct=getAuthAccount(address)
let holderRef = acct.borrow<&LockedTokens.TokenHolder>(from: LockedTokens.TokenHolderStoragePath) ?? panic("TokenHolder is not saved at specified path")
let delegatorNodeID = holderRef.getDelegatorNodeID() ?? panic("could not get delegator node id")
let delegatorID = holderRef.getDelegatorID() ?? panic("could not get delegator id")
return FlowIDTableStaking.DelegatorInfo(nodeID: delegatorNodeID, delegatorID: delegatorID)
}
英文:
import LockedTokens from 0x8d0e87b65159ae63
import FlowIDTableStaking from 0x8624b52f9ddcd04a
pub fun main(address:Address) : FlowIDTableStaking.DelegatorInfo {
let acct=getAuthAccount(address)
let holderRef = acct.borrow<&LockedTokens.TokenHolder>(from: LockedTokens.TokenHolderStoragePath) ?? panic("TokenHolder is not saved at specified path")
let delegatorNodeID = holderRef.getDelegatorNodeID() ?? panic("could not get delegator node id")
let delegatorID = holderRef.getDelegatorID() ?? panic("could not get delegator id")
return FlowIDTableStaking.DelegatorInfo(nodeID: delegatorNodeID, delegatorID: delegatorID)
}
This code is dervied from several scripts over here https://github.com/onflow/flow-core-contracts/tree/master/transactions
You have to call that script in any flow SDK and it should give you out the DelegatorInfo struct defined here https://github.com/onflow/flow-core-contracts/blob/3198bb0d01351daaf207e82c930da5fc0cc60fa8/contracts/FlowIDTableStaking.cdc#L379
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论