CRYPTO NEWS

Finance Redefined: Three Arrow Capital and Celsius fall brings a tsunami of sell-off in DeFi

DeFi market saw a sharp decline in its TVL, falling over $25 billion from the last week due to sell-off pressure created by the bear market.

Handling different logic with Chainlink VRF

I’m trying to use chainlink VRF to handle different logic. In essence, I want the fulfill random words to do something depending on the function that made the request. E.g uint256 public A; uint256 public B; function doLogicA() public{ //Makes a request for a random number } function doLogicB() public{ //Also makes a request for::Listen

I’m trying to use chainlink VRF to handle different logic. In essence, I want the fulfill random words to do something depending on the function that made the request.

E.g

  uint256 public A;  uint256 public B;   function doLogicA() public{    //Makes a request for a random number   }   function doLogicB() public{    //Also makes a request for a random number  }   function fulfillRandomWords() internal override(requestId, randomWords){   // If dologicB made the request update storage variable B  // If dologicA made the request update storage variable A } ' 

My thoughts on this is probably to use a mapping to keep track of which function made the request with a functionId(a hash or uint256) with the request Id given to us from the request E.g

mapping(uint256 => uint256) public requestIdToFunctionId; 

Then in the fulfillRandomWords we could have some if logics E.g Let’s take doLogicB function Id to be 1 and dologicA 2.(Hashing their names would probably be better). Our fulfillRandomWords function could look like this?

function fulfillRandomWords (requestId, randomWords ) internal override {  If(requestIdToFunctionId [requestId] == 1){    //Do logic B  }  If(requestIdToFunctionId [requestId] == 2){    //Do logic A  } } 

It’s a bit tedious especially if we’re gonna keep track of individual users or tokenId’s but I think it’s doable with a nonce. Then we’d have mappings of requestId to FunctionId to user to nonce. Lol! Awesome! But I wanted to know if there was a better way of doing this. P.s I apologize if I wasn’t so clear on the question, I’m on the road. It popped in my head. Didn’t want it to leave!

Finance Redefined: Three Arrow Capital and Celsius fall brings a tsunami of sell-off in DeFi

Shopping cart
There are no products in the cart!
Continue shopping
0