使用user_id以编程方式检索Flow中用户的当前委托和奖励。

huangapple go评论46阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月5日 14:06:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定