Code Monkey home page Code Monkey logo

Comments (4)

bkchr avatar bkchr commented on July 23, 2024

CC @KiChjang

from polkadot.

KiChjang avatar KiChjang commented on July 23, 2024

In order to make use of ensure_xcm, let's first take a look at the code:

pub fn ensure_xcm<OuterOrigin>(o: OuterOrigin) -> Result<MultiLocation, BadOrigin>
// ...
{
	match o.into() {
		Ok(Origin::Xcm(location)) => Ok(location),
		// ...
	}
}

Here you can see that it's trying to convert the OuterOrigin (we call it RuntimeOrigin nowadays) into an Origin::Xcm variant. This means that the MultiLocation origin must have been converted to a FRAME origin before by an origin converter. Currently, there is a single origin converter that does this, and it's called XcmPassthrough, located in the XCM pallet.

In short, ensure_xcm only works if you have specifically configured your OriginConverter to be XcmPassthrough, otherwise you will never be able to get an Origin::Xcm to match against.

from polkadot.

hqwangningbo avatar hqwangningbo commented on July 23, 2024

@KiChjang Ok, so that's the case, thanks for the answer.

I would like to ask, for example, if I want to write a pallet with a test_call method in it, and another chain calls it via DescendOrigin+Trancact instruction, what operation can I use to get the para_id, caller, and other useful information of the calling chain in the test_call method ?

from polkadot.

KiChjang avatar KiChjang commented on July 23, 2024

The most direct way of doing so is to include them as parameters to test_method. Outside of that, XcmPassthrough has the MultiLocation of the sender, so you can quickly check and see which parachain it came from by matching agains the Parachain junction.

from polkadot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.